About 189,000 results
Open links in new tab
  1. Find if HashMap contains chosen value and return key

    Aug 13, 2015 · Is there any way to find if my HashMap<String, String> contains entry ( key,value) with value="x" and to go through all entries sequentially ?

  2. java - Key existence check in HashMap - Stack Overflow

    Is checking for key existence in HashMap always necessary? I have a HashMap with say a 1000 entries and I am looking at improving the efficiency. If the HashMap is being accessed very frequently, ...

  3. java - Hashmap contains key - Stack Overflow

    Jun 22, 2013 · I found this program in my text book, which basically counts the occurence of each string in the String array tst. public class Test { private static HashMap&lt;String, Integer&gt; mp = new …

  4. What is the time complexity of HashMap.containsKey() in java?

    Jan 19, 2012 · From the API doc of HashMap: This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly …

  5. java - If HashMap containskey (Any part of a String) - Stack Overflow

    Mar 6, 2019 · Find a different data structure; use a for loop on the "parts" of your String; your HashMap is organized by the hashCode() of the key (s) in it.

  6. java - Efficient way to find if map contains any of the keys from a ...

    Dec 28, 2012 · I need to check if a map contains any of the keys from a list, and if it does then return the first matching value. The naive approach that comes to mind is to do it in two nested loops: Map&lt;St...

  7. Java HashMap get works but containsKey does not

    Oct 2, 2015 · The reason why get (Object) is working is, that HashMap will calculate the Hash for your Location class and returns the Object the hascode points to. containsKey (Object) calculates the …

  8. java - ArrayList.contains () vs HashMap.containsKey () vs HashMap.get ...

    Oct 26, 2014 · Does ArrayList.contains () have to iterate over all items to do its check? Does HashMap.containsKey ()? I know HashMap.get () doesn't need to, but is that why it is the most …

  9. Is using java Map.containsKey() redundant when using map.get()

    Jan 30, 2013 · I have been wondering for some time whether it is allowable within best practice to refrain from using the containsKey() method on java.util.Map and instead do a null check on the result from …

  10. Java HashMap containsKey - Stack Overflow

    Jul 13, 2020 · When you add a key to the map, it stores the hash code. When you try to find a key, the map asks for the hash code of the key you're trying to find, and efficiently finds any entries with the …