There's public static class AbstractMap.SimpleEntry<K,V>. Don't let the Abstract part of the name mislead you: it is in fact NOT an abstract class (but its top-level AbstractMap is).

The fact that it's a static nested class means that you DON'T need an enclosing AbstractMap instance to instantiate it, so something like this compiles fine:

Map.Entry<String,Integer> entry =
    new AbstractMap.SimpleEntry<String, Integer>("exmpleString", 42);

As noted in another answer, Guava also has a convenient static factory method Maps.immutableEntry that you can use.


You said:

I can't use Map.Entry itself because apparently it's a read-only object that I can't instantiate new instanceof

That's not entirely accurate. The reason why you can't instantiate it directly (i.e. with new) is because it's an interface Map.Entry.


Caveat and tip

As noted in the documentation, AbstractMap.SimpleEntry is @since 1.6, so if you're stuck to 5.0, then it's not available to you.

To look for another known class that implements Map.Entry, you can in fact go directly to the javadoc. From the Java 6 version

Interface Map.Entry

All Known Implementing Classes:

  • AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry

Unfortunately the 1.5 version does not list any known implementing class that you can use, so you may have be stuck with implementing your own.

Answer from polygenelubricants on Stack Overflow
Top answer
1 of 12
987

There's public static class AbstractMap.SimpleEntry<K,V>. Don't let the Abstract part of the name mislead you: it is in fact NOT an abstract class (but its top-level AbstractMap is).

The fact that it's a static nested class means that you DON'T need an enclosing AbstractMap instance to instantiate it, so something like this compiles fine:

Map.Entry<String,Integer> entry =
    new AbstractMap.SimpleEntry<String, Integer>("exmpleString", 42);

As noted in another answer, Guava also has a convenient static factory method Maps.immutableEntry that you can use.


You said:

I can't use Map.Entry itself because apparently it's a read-only object that I can't instantiate new instanceof

That's not entirely accurate. The reason why you can't instantiate it directly (i.e. with new) is because it's an interface Map.Entry.


Caveat and tip

As noted in the documentation, AbstractMap.SimpleEntry is @since 1.6, so if you're stuck to 5.0, then it's not available to you.

To look for another known class that implements Map.Entry, you can in fact go directly to the javadoc. From the Java 6 version

Interface Map.Entry

All Known Implementing Classes:

  • AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry

Unfortunately the 1.5 version does not list any known implementing class that you can use, so you may have be stuck with implementing your own.

2 of 12
235

Starting from Java 9, there is a new utility method allowing to create an immutable entry which is Map#entry(Object, Object).

Here is a simple example:

Entry<String, String> entry = Map.entry("foo", "bar");

As it is immutable, calling setValue will throw an UnsupportedOperationException. The other limitations are the fact that it is not serializable and null as key or value is forbidden, if it is not acceptable for you, you will need to use AbstractMap.SimpleImmutableEntry or AbstractMap.SimpleEntry instead.

NB: If your need is to create directly a Map with 0 to up to 10 (key, value) pairs, you can instead use the methods of type Map.of(K key1, V value1, ...).

🌐
Baeldung
baeldung.com › home › java › java collections › java map › how to create a new entry in a map
How to Create a New Entry in a Map | Baeldung
January 8, 2024 - Learn how to use Java's built-in classes, third-party libraries, and a custom implementation to create an Entry object in a Map.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Map.Entry.html
Map.Entry (Java Platform SE 8 )
3 weeks ago - Java™ Platform Standard Ed. 8 ... A map entry (key-value pair). The Map.entrySet method returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view.
🌐
GeeksforGeeks
geeksforgeeks.org › java › map-entry-interface-java-example
Map.Entry interface in Java with example - GeeksforGeeks
January 22, 2026 - The enhanced for loop iterates over each Map.Entry. ... import java.util.HashMap; import java.util.Map; public class GFG { public static void main(String[] args) { Map<String, Integer> map = new HashMap<>(); map.put("Java", 1); map.put("Python", 2); map.put("C++", 3); for (Map.Entry<String, Integer> e : map.entrySet()) { System.out.print(e.getValue()+" "); } } }
🌐
Baeldung
baeldung.com › home › java › java collections › java map › using the map.entry java class
Using the Map.Entry Java Class | Baeldung
January 8, 2024 - We often use maps to store a collection of key-value pairs. We explore the Entry objects inside a map and how to make the most of them.
🌐
Coderanch
coderanch.com › t › 755986 › java › Create-Map-existing-List-Entry
Create a Map out of existing List of Entry (Java in General forum at Coderanch)
November 28, 2022 - shell> Map.Entry<String, String> e = myList.get(0); e ==> Year=Year1 jshell> e.getClass() $13 ==> class java.util.KeyValueHolder jshell> e.getClass().getSuperclass() $14 ==> class java.lang.Object At this point I gave up; I don't understand what is going on
🌐
Medium
medium.com › @AlexanderObregon › javas-map-entryset-method-explained-1526a8cd58fb
Java’s Map.entrySet() Method Explained | Medium
December 15, 2024 - However, the behavior depends on the specific implementation of the map: HashMap: Allows one null key and multiple null values. TreeMap: Throws a NullPointerException if the comparator or natural ordering is used and a null key is added. ConcurrentHashMap: Does not permit null keys or values. When iterating over the entries, you should account for possible null keys or values, particularly if your logic involves comparisons or calculations. ... import java.util.HashMap; import java.util.Map; public class NullHandlingExample { public static void main(String[] args) { Map<String, String> userDet
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › Map.Entry.html
Map.Entry (Java SE 17 & JDK 17)
January 20, 2026 - An instance obtained from a map's entry-set view has a connection to that map. The copyOf method may be used to create a Map.Entry instance, containing the same key and value, that is independent of any map.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › java map entry
Java Map Entry - Scaler Topics
May 4, 2023 - Once we've stored a key-value pair ... the associated value. Now, each key value tuple that is added to a map is referred to as an "entry" (i.e., a key, along with its associated value)....
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › AbstractMap.SimpleEntry.html
AbstractMap.SimpleEntry (Java Platform SE 7 )
This class facilitates the process of building custom map implementations. For example, it may be convenient to return arrays of SimpleEntry instances in method Map.entrySet().toArray. ... Creates an entry representing a mapping from the specified key to the specified value.
🌐
Tutorialspoint
tutorialspoint.com › java › java_mapentry_interface.htm
Java - The Map.Entry Interface
Following is an example showing how Map.Entry can be used to get key of a map entry − · import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class HashMapDemo { public static void main(String args[]) { // Create a hash map HashMap<String, Double> hm = new HashMap<>(); // Put elements to the map hm.put("Zara", Double.valueOf(3434.34)); hm.put("Mahnaz", Double.valueOf(123.22)); hm.put("Ayan", Double.valueOf(1378.00)); hm.put("Daisy", Double.valueOf(99.22)); hm.put("Qadir", Double.valueOf(-19.08)); // Get a set of the entries Set<Map.Entry<String, Double>> set = hm.entrySet(); // Get an iterator Iterator<Map.Entry<String, Double>> i = set.iterator(); // Display elements while(i.hasNext()) { Map.Entry<String, Double> me = i.next(); System.out.println(me.getKey()); } } }
🌐
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › util › Map.Entry.html
Map.Entry (Java SE 23 & JDK 23 [build 1])
An instance obtained from a map's entry-set view has a connection to that map. The copyOf method may be used to create a Map.Entry instance, containing the same key and value, that is independent of any map.
🌐
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › util › Map.Entry.html
Map.Entry (Java SE 19 & JDK 19 [build 1])
An instance obtained from a map's entry-set view has a connection to that map. The copyOf method may be used to create a Map.Entry instance, containing the same key and value, that is independent of any map.
🌐
Mpg
resources.mpi-inf.mpg.de › d5 › teaching › ss05 › is05 › javadoc › java › util › HashMap.Entry.html
java.util Class HashMap.Entry
Create new entry. ... Returns the key corresponding to this entry. ... Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › › java.base › java › util › Map.Entry.html
Map.Entry (Java SE 21 & JDK 21)
January 20, 2026 - An instance obtained from a map's entry-set view has a connection to that map. The copyOf method may be used to create a Map.Entry instance, containing the same key and value, that is independent of any map.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › AbstractMap.SimpleEntry.html
AbstractMap.SimpleEntry (Java Platform SE 8 )
3 weeks ago - This class facilitates the process of building custom map implementations. For example, it may be convenient to return arrays of SimpleEntry instances in method Map.entrySet().toArray. ... Creates an entry representing a mapping from the specified key to the specified value.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › initialize a hashmap in java
Initialize a HashMap in Java | Baeldung
September 7, 2024 - As we’ve looked into the ways of using core Java, let’s move ahead and initialize a map using the Guava library: Map<String, String> articles = ImmutableMap.of("Title", "My New Article", "Title2", "Second Article"); This would create an immutable map, and to create a mutable one:
🌐
Programiz
programiz.com › java-programming › library › hashmap › entryset
Java HashMap entrySet()
import java.util.HashMap; class Main { public static void main(String[] args) { // create an HashMap HashMap<String, Integer> prices = new HashMap<>(); // insert entries to the HashMap prices.put("Shoes", 200); prices.put("Bag", 300); prices.put("Pant", 150); System.out.println("HashMap: " + prices); // return set view of mappings System.out.println("Set View: " + prices.entrySet()); } }
🌐
Android Developers
developer.android.com › api reference › map.entry
Map.Entry | API reference | Android Developers
February 13, 2026 - Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
GeeksforGeeks
geeksforgeeks.org › java › map-entryset-method-in-java-with-examples
Map entrySet() method in Java with Examples - GeeksforGeeks
January 27, 2026 - Each Map.Entry represents a single key–value pair from the map. It allows simultaneous access to both keys and values during iteration. More efficient than keySet() when values are also required, as it avoids extra get() calls. ... import java.util.*; class GFG { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(1, "Java"); map.put(2, "Python"); for (Map.Entry<Integer, String> e : map.entrySet()) { System.out.println(e.getKey() + " : " + e.getValue()); } } }