About 50 results
Open links in new tab
  1. java - Correct way to initialize HashMap and can HashMap hold …

    A HashMap can hold any object as a value, even if it is another HashMap. Eclipse is suggesting that you declare the types because that is the recommended practice for Collections. under Java 5.

  2. What are the differences between a HashMap and a Hashtable in Java?

    HashTable and HashMap are member of the Java Collections Framework (since Java 2 platform v1.2, HashTable was retrofitted to implement the Map interface). HashTable is considered legacy code, …

  3. Get keys from HashMap in Java - Stack Overflow

    May 5, 2012 · A HashMap contains more than one key. You can use keySet() to get the set of all keys.

  4. Java Hashmap: How to get key from value? - Stack Overflow

    Sep 6, 2009 · If I have the value "foo", and a HashMap<String> ftw for which ftw.containsValue("foo") returns true, how can I get the corresponding key? Do I have to loop through the hashmap? What is …

  5. java - How to directly initialize a HashMap (in a literal way)? - Stack ...

    Java 9 added a series of Map.of static methods to do just what you want: Instantiate an immutable Map using literal syntax. The map (a collection of entries) is immutable, so you cannot add or remove …

  6. java - Iterate through a HashMap - Stack Overflow

    Jul 1, 2009 · Since all maps in Java implement the Map interface, the following techniques will work for any map implementation (HashMap, TreeMap, LinkedHashMap, Hashtable, etc.) Method #1: …

  7. java - How to update a value, given a key in a hashmap? - Stack Overflow

    805 Suppose we have a HashMap<String, Integer> in Java. How do I update (increment) the integer-value of the string-key for each existence of the string I find? One could remove and reenter the pair, …

  8. What is the difference between the HashMap and Map objects in Java?

    Jan 5, 2017 · There is no difference between the objects; you have a HashMap<String, Object> in both cases. There is a difference in the interface you have to the object. In the first case, the interface is …

  9. java - How to get values and keys from HashMap? - Stack Overflow

    Apr 27, 2013 · Map is internally made up of Map.Entry objects. Each Entry contains key and value. To get key and value from the entry you use accessor and modifier methods. If you want to get values …

  10. Is a Java hashmap search really O (1)? - Stack Overflow

    Aug 15, 2020 · In java.util.HashMap, the alpha constant relates to the load factor parameter on the constructor. Though not exactly, because the number of buckets is quantized by the way that …