About 296,000 results
Open links in new tab
  1. dictionary - Create Map in Java - Stack Overflow

    Feb 7, 2013 · I'd like to create a map that contains entries consisting of (int, Point2D) How can I do this in Java? I tried the following unsuccessfully. HashMap hm = new HashMap(); hm.put(1, …

  2. 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 …

  3. collections - Java Ordered Map - Stack Overflow

    Is there an object in Java that acts like a Map for storing and accessing key/value pairs, but can return an ordered list of keys and an ordered list of values, such that the key and value lists ar...

  4. How do I make a Map<String, List<String> unmodifiable?

    Sep 30, 2013 · The java.util.Collections class allows me to make collection instances unmodifiable. The following method protected Map<String, List<String>> getCacheData () { …

  5. java - How to convert List to Map? - Stack Overflow

    List differs from Map in the conceptual way -- Map have notion of 'key, value' pair, whereas List doesn't. Given this it's unclear how exactly you going to convert from List to Map and back.

  6. Create 2D map on which objects can be placed and move in Java

    4 I am new to Java and I'm trying to make a 2D text-based game that internally consists of a world map on which objects can interact and move. However, I'm already confused at the very …

  7. How to create a HashMap with two keys (Key-Pair, Value)?

    Java 7+ contains a new Map.Entry<K,V> class that you can use as key for your map (or entry for your set). Java 9+ also contains a Map.entry(K k, V v) method to easily create new Map.Entry …

  8. java - How can I initialise a static Map? - Stack Overflow

    Feb 3, 2009 · How would you initialise a static Map in Java? Method one: static initialiser Method two: instance initialiser (anonymous subclass) or some other method? What are the pros and …

  9. Java - How to create new Entry (key, value) - Stack Overflow

    Jun 24, 2010 · 433 I'd like to create new item that similarly to Util.Map.Entry that will contain the structure key, value. The problem is that I can't instantiate a Map.Entry because it's an …

  10. Map inside a map in Java - Stack Overflow

    Jul 9, 2021 · map.put("AAA", innerMap); But as of Java 8 you can create the map as a value if it doesn't exist which is then returned using computeIfAbsent If the value (i.e. map) doesn't exist …