Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A KeyValuePair in Java [duplicate]

Tags:

java

key-value

I'm looking for a KeyValuePair class in Java.
Since java.util heavily uses interfaces there is no concrete implementation provided, only the Map.Entry interface.

Is there some canonical implementation I can import? It is one of those "plumbers programming" classes I hate to implement 100x times.

like image 892
maayank Avatar asked Oct 05 '22 12:10

maayank


2 Answers

The class AbstractMap.SimpleEntry is generic and can be useful.

like image 269
Eyal Schneider Avatar answered Oct 17 '22 08:10

Eyal Schneider


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"
like image 107
kreker Avatar answered Oct 17 '22 09:10

kreker