The class AbstractMap.SimpleEntry is generic and can be useful.
Answer from Eyal Schneider on Stack Overflow Top answer 1 of 10
275
The class AbstractMap.SimpleEntry is generic and can be useful.
2 of 10
113
Android programmers could use BasicNameValuePair
Update:
BasicNameValuePair is now deprecated (API 22). Use Pair instead.
Example usage:
Pair<Integer, String> simplePair = new Pair<>(42, "Second");
Integer first = simplePair.first; // 42
String second = simplePair.second; // "Second"
Baeldung
baeldung.com › home › java › core java › using pairs in java
Using Pairs in Java | Baeldung
March 13, 2024 - In summary, Pair is best suited for handling a single key-value association or when returning two related values from a method. HashMap, however, is more appropriate for cases that involve storing multiple key-value pairs and require efficient data retrieval and modification capabilities. We can find the Pair class in the javafx.util package.
How to Add Key-Value Pair to HashMap ONLY IF NOT Present - YouTube
How to Add Key-Value Pairs in a HashMap Using Core Java - YouTube
00:33
Master Key-Value Pairs with MAP: Java Explained - YouTube
10:44
Introduction to Maps in Java - Exploring Key-Value Pair Data ...
Key-Value Pair in Java Collections with Example
13:51
How to Put a Key-Value pair in a HashTable? | Part 1 | Separate ...
Delft Stack
delftstack.com › home › howto › java › java key value pair
How to Implement Key Value Pair in Java | Delft Stack
February 12, 2024 - The Properties method provides a concise and effective way to implement key-value pairs in Java, particularly for configuration settings. Its simplicity makes it an excellent choice for scenarios where you need to store and retrieve key-value pairs without the complexity of other data structures. It is often used for reading and writing configuration files, making it a versatile tool for storing and retrieving key-value pairs. By using the Properties class, you gain a versatile tool for managing configuration settings and other key-value data in your Java applications.
Oracle
docs.oracle.com › middleware › 12212 › wcs › java-ref › com › fatwire › rest › beans › KeyValuePair.html
KeyValuePair (Oracle WebCenter Sites Java API Reference)
Java class for keyValuePair complex type. The following schema fragment specifies the expected content contained within this class. <complexType name="keyValuePair"> <complexContent> <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> <sequence> <element name="key" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> <element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> </sequence> </restriction> </complexContent> </complexType> clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait ·
GeeksforGeeks
geeksforgeeks.org › java › keyvalue-class-in-java-tuples
KeyValue Class in JavaTuples - GeeksforGeeks
July 11, 2025 - KeyValue<type1, type2> kv = new KeyValue<type1, type2>(value1, value2); KeyValue<type1, type2> kvNew = kv.setKey(valueNew); ... // Below is a Java program to set // a KeyValue Key import java.util.*; import org.javatuples.KeyValue; class GfG { public static void main(String[] args) { KeyValue<Integer, String> kv = KeyValue.with(Integer.valueOf(1), "GeeksforGeeks"); KeyValue<Integer, String> otherKeyValue = kv.setKey(10); System.out.println(otherKeyValue); } }
Apache Kafka
kafka.apache.org › 26 › javadoc › org › apache › kafka › streams › KeyValue.html
KeyValue (kafka 2.6.0 API)
java.lang.Object · org.apache.kafka.streams.KeyValue<K,V> Type Parameters: K - Key type · V - Value type · public class KeyValue<K,V> extends Object · A key-value pair defined for a single Kafka Streams record. If the record comes directly from a Kafka topic then its key/value are defined ...
BeginnersBook
beginnersbook.com › 2013 › 12 › hashmap-in-java-with-example
HashMap in Java With Examples
September 19, 2022 - HashMap is a Map based collection class that is used for storing Key & value pairs, it is denoted as HashMap<Key, Value> or HashMap<K, V>. HashMap in java, is similar to the Hashtable class except that it is unsynchronized and permits nulls(null values and null key).
AWS
docs.aws.amazon.com › AWSJavaSDK › latest › javadoc › com › amazonaws › services › ecs › model › KeyValuePair.html
KeyValuePair (AWS SDK for Java - 1.12.797)
@Generated(value="com.amazonaws:aws-java-sdk-code-generator") public class KeyValuePair extends Object implements Serializable, Cloneable, StructuredPojo · A key-value pair object.
Top answer 1 of 3
4
personally i wouldn't, i like the built-in collections just fine.
having said that...
- if you want something with better performance/smaller in-memory size, have a look at trove. they have map implementations that do away with the extra Entry (key-value pair) class. theyre especially good if your keys or values are primitives (say, ints)
- if you want something with better predictability (another performance aspect), have a look at javolution. their collections classes offer much better worst-case times (think what happens when you insert something into a standard collection and you just triggered a resize...)
- if youre looking for collections classes with more features, have a look at guava
2 of 3
2
Try Generics and create your own class if you don't like java collections:
public class Pair<K, V> {
private K key;
private V value;
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public void setKey(K key) {
this.key = key;
}
public V getValue() {
return value;
}
public void setValue(V value) {
this.value = value;
}
public static void main(String[] args) {
Pair<String, String> pair = new Pair<String, String>("key", "value");
System.out.println(pair.getKey());
System.out.println(pair.getValue());
}
}
GeeksforGeeks
geeksforgeeks.org › java › java-util-hashmap-in-java-with-examples
HashMap in Java - GeeksforGeeks
The arrow labeled Implements indicates that HashMap provides the implementation of the methods defined by Map. HashMap stores data in the form of key-value pairs, where each key is unique.
Published: August 31, 2026
Dev.java
dev.java › learn › api › collections-framework › maps
Using Maps to Store Key Value Pairs - Dev.java
September 14, 2021 - Indeed, a SortedMap shares the same kind of semantics as the SortedSet: a SortedMap is a map that keeps its key-value pairs sorted by their keys. The same goes for NavigableMap: the methods added by this interface are the same kind of methods than the ones added by NavigableSet to SortedSet. The JDK gives you several implementations of the Map interface, the most widely used is the HashMap class.
Princeton CS
introcs.cs.princeton.edu › java › code › javadoc › ST.html
Class ST<Key extends Comparable<Key>,Value>
The ST class represents an ordered symbol table of generic key-value pairs. It supports the usual put, get, contains, remove, size, and is-empty methods. It also provides ordered methods for finding the minimum, maximum, floor, and ceiling. It also provides a keys method for iterating over ...
Top answer 1 of 3
4
You will need to create your own. This is done (AFAIK) to facilitate a better semantic meaning from the class name, than a general Pair<> or KeyValuePair<> would
2 of 3
2
http://docs.oracle.com/javase/7/docs/api/java/util/Map.Entry.html
and an implementation from SO Java - How to create new Entry (key, value)
Microsoft Learn
learn.microsoft.com › en-us › java › api › com.azure.resourcemanager.chaos.models.keyvaluepair
KeyValuePair Class | Microsoft Learn
Creates an instance of KeyValuePair class. public static KeyValuePair fromJson(JsonReader jsonReader) Reads an instance of KeyValuePair from the JsonReader. ... An instance of KeyValuePair if the JsonReader was pointing to an instance of it, or null if it was pointing to JSON null. ... IOException - If the deserialized JSON object was missing any required properties. ... Get the key property: The name of the setting for the action. ... Validates the instance. ... Get the value property: The value of the setting for the action.
Oracle
docs.oracle.com › middleware › 1213 › oer › OEREF › com › flashline › registry › openapi › entity › KeyValuePair.html
KeyValuePair (Oracle© Fusion Middleware Extensibility Framework (REX) for Oracle Enterprise Repository)
public class KeyValuePair extends java.lang.Object implements java.io.Serializable · See Also: Serialized Form · clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait · public KeyValuePair() public KeyValuePair(java.lang.String key, java.lang.String value) public java.lang.String getKey() Gets the key value for this KeyValuePair.