🌐
W3Schools
w3schools.com › java › java_map.asp
Java Map
The Map interface is a part of the Java Collections Framework and is used to store key-value pairs.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Map.html
Map (Java Platform SE 8 )
July 21, 2026 - An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › difference between map.ofentries() and map.of()
Difference Between Map.ofEntries() and Map.of() | Baeldung
January 8, 2024 - Take a closer look at these two static factory methods for immutable maps and explain which one is suitable for which purpose.
🌐
Foojay
foojay.io › home › java core › comparing map.of() and new hashmap() in java
Comparing Map.of() and new HashMap() in Java
March 17, 2023 - Map.of() is a method introduced in Java 9, which allows developers to create an immutable map with up to 10 key-value pairs.
🌐
GeeksforGeeks
geeksforgeeks.org › java › map-interface-in-java
Map Interface in Java - GeeksforGeeks
In Java, the Map Interface is part of the java.util package and represents a collection of key-value pairs, where Keys should be unique, but values can be duplicated.
Published: August 31, 2026
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › Map.html
Map (Java SE 11 & JDK 11 )
January 20, 2026 - An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
🌐
Javacodehouse
javacodehouse.com › blog › java-map-of
Creating Immutable Maps with Java
January 24, 2024 - However, there are some differences in terms of flexibility and use cases. ... Map.of(): This method allows you to create a map with up to 10 key-value pairs.
🌐
W3Schools
w3schools.com › java › java_hashmap.asp
Java HashMap
Java Examples Java Videos Java ... Java Syllabus Java Study Plan Java Interview Q&A ... A HashMap stores items in key/value pairs, where each key maps to a specific value....
Top answer
1 of 3
75

Any guesses on how would you create a Map of 26 elements?

The primary difference between the two factory methods in Map that you already linked is that :

Map.ofEntries

Returns an immutable map containing keys and values extracted from the given entries (that are not bounded in count)

From the JEP-269:Convenience Factory Methods for Collections:

For larger numbers of entries, an API will be provided that will create a Map instance given an arbitrary number of key-value pairs:

Map.ofEntries(Map.Entry<K,V>...)

While this approach is analogous to the equivalent varargs APIs for List and Set, it unfortunately requires that each key-value pair be boxed. A method for boxing keys and values, suitable for static import, will make this more convenient:

Map.Entry<K,V> entry(K k, V v)

Your assumption about the method .of() from Map is somewhat incorrect probably because while this would compile with Java9:

List<Integer> values = List.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // note 11 elements here

Set<String> keys = Set.of("z", "o", "tw", "th", "fo", "fi", "si", "se", "e", "n", "te");

This, on the other hand, wouldn't:

Map<String, Integer> map = Map.of("z", 0, "o", 1,
      "tw", 2, "th", 3, "fo", 4, "fi", 5,
      "si", 6, "se", 7, "e", 8, "n", 9, "te", 10); // this would not compile

The reason for that is since there is a varargs implementation for List.of and Set.of but to create a similar API for Map both the keys and values were supposed to be boxed as stated in the JEP as well. So, the same was created using varargs of type Map.entry() as:

Map<String, Integer> map = Map.ofEntries(Map.entry("z",0),
       Map.entry("o",1),Map.entry("t",2)...so on);

Furthermore from the documentation of Map.entry() which is also introduced Since:9 -

Returns an immutable Map.Entry containing the given key and value. These entries are suitable for populating Map instances using the Map.ofEntries() method.

The Entry instances created by this method have the following characteristics:

  • They disallow null keys and values. Attempts to create them using a null key or value result in NullPointerException.

  • They are immutable. Calls to Entry.setValue() on a returned Entry result in UnsupportedOperationException.

  • They are not serializable.

  • They are value-based. Callers should make no assumptions about the identity of the returned instances. This method is free to create new instances or reuse existing ones. Therefore, identity-sensitive operations on these instances (reference equality (==), identity hash code, and synchronization) are unreliable and should be avoided.

which are similar to the characteristics of Immutable Map Static Factory Methods introduced recently.

2 of 3
19

Java 9 introduced creating small unmodifiable Collection instances using a concise one line code, for maps the signature of factory method is:

static <K,V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)

This method is overloaded to have 0 to 10 key-value pairs, e.g.

Map<String, String> map = Map.of("1", "first");
Map<String, String> map = Map.of("1", "first", "2", "second");
Map<String, String> map = Map.of("1", "first", "2", "second", "3", "third");

Similarly you can have up to ten entries.

For a case where we have more than 10 key-value pairs, there is a different method:

static <K,V> Map<K,V> ofEntries(Map.Entry<? extends K,? extends V>... entries)

Here is the usage.

Map<String, String> map = Map.ofEntries(
  new AbstractMap.SimpleEntry<>("1", "first"),
  new AbstractMap.SimpleEntry<>("2", "second"),
  new AbstractMap.SimpleEntry<>("3", "third"));
Find elsewhere
🌐
Redisson
redisson.pro › glossary › java-map.html
What is a Java map? | Redisson
Java maps are an implementation of the map abstract data type for the Java programming language. Maps link keys with values: given a key, the map will return the associated value. Each key is unique, but the associated values may not be.
🌐
Stackify
stackify.com › an-introduction-to-java-map-what-it-is-and-how-it-works
An Introduction to Java Map: What It Is and How It Works - Stackify
November 26, 2024 - The following classes implement the Java Map interface, each with unique characteristics: HashMap provides an efficient, unordered key-value mapping, with average constant-time complexity for insertions and lookups · TreeMap maintains keys in sorted, natural order (or by a custom comparator), which is ideal for scenarios where order matters · LinkedHashMap retains insertion order, which is useful when you want a predictable iteration order ... The Map interface is often misunderstood as being a subtype of the Collection interface.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › Map.html
Map (Java SE 21 & JDK 21)
January 20, 2026 - An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
🌐
CodeSignal
codesignal.com › learn › courses › mastering-complex-data-structures-in-java › lessons › exploring-maps-and-hashmap-in-java
Exploring Maps and HashMap in Java
In the above code, we create a PhoneBook class that uses a HashMap to store contacts. As you can see, Maps simplify the processes of adding, modifying, and accessing information with unique keys. Java Maps enable a variety of operations for manipulating data, such as adding, retrieving, and deleting key-value pairs, and more.
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › util › Map.html
Map (Java SE 9 & JDK 9 )
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
🌐
DEV Community
dev.to › wittedtech-by-harshit › a-deep-dive-into-java-maps-the-ultimate-guide-for-all-developers-oig
A Deep Dive into Java Maps: The Ultimate Guide for All Developers - DEV Community
November 12, 2024 - Counting Frequencies : Count occurrences of elements (e.g., word frequencies). Maps shine in scenarios where quick lookups, inserts, and updates are needed. They are used to model relationships where a unique identifier (key) is associated with a specific entity (value). Java provides a variety of Maps to suit different needs: 3.1 HashMap
🌐
Jenkov
jenkov.com › tutorials › java-collections › map.html
Java Map
The HashMap implementation is typically the fastest of the two Map implementations, so whenever you don't need to sort the elements in the Map you can just use a HashMap. Otherwise use a TreeMap. To create a Java Map you must create an instance of one the classes that implement the Java Map interface.
🌐
Medium
medium.com › threadsafe › java-maps-simplified-understanding-mutable-vs-immutable-implementations-7bd848dde161
Java Maps Simplified: Understanding Mutable vs. Immutable Implementations | by Alireza Alimohammadi | ThreadSafe | Medium
June 29, 2025 - In this article, we will explore how to declare and initialize a map in Java, discuss the differences between immutable and mutable maps, and explain why assigning the result of Map.of() to a HashMap is not permitted, and compare their available methods.
🌐
Tutorialspoint
tutorialspoint.com › java › java_map_interface.htm
Java - Map Interface
The following are the classes that implement a Map to use the functionalities of a Map - ... Map has its implementation in various classes like HashMap. Following is an example to explain map functionality − · import java.util.HashMap; import java.util.Map; public class CollectionsDemo { public static void main(String[] args) { Map<String, String> m1 = new HashMap<>(); m1.put("Zara", "8"); m1.put("Mahnaz", "31"); m1.put("Ayan", "12"); m1.put("Daisy", "14"); System.out.println(); System.out.println(" Map Elements"); System.out.print("\t" + m1); } }
🌐
JanBask Training
janbasktraining.com › community › java › explain-java-map-of-maps1
Explain java map of maps. | JanBask Training Community
November 14, 2022 - in the project I am currently working on we had three different types of prices depending on the age of the user (adult, child, etc...). So we had on the DB a table looking like this: ... Where the keys were the price type. Recently, they added a new business rule that adds 3 subtypes to every price type, so now we have something like this: ... Regarding the Java map of maps - Both nested and combined keys have their places.
🌐
W3Schools
w3schools.com › java › java_ref_hashmap.asp
Java HashMap Reference
The complete reference of Java HashMap methods, with descriptions and examples.