java arraylist of pairs

Solutions on MaxInterview for java arraylist of pairs by the best coders in the world

showing results for - "java arraylist of pairs"
Charles
10 Feb 2016
1List<Pair<Integer,String>> pairList = new ArrayList<Pair<Integer,String>>();
2
3public class Pair<Key,Value> {
4    private Key key;
5    private Value value;
6
7    public Pair(Key key, Value value){
8        this.key = key;
9        this.value = value;
10    }
11
12    public Key getKey(){ return this.key; }
13    public Value getValue(){ return this.value; }
14
15    public void setKey(Key key){ this.key = key; }
16    public void setValue(Value value){ this.value = value; }
17}
18//Notice that it doesn't have to be in a "Key-Value" fashion, it can be any 2 variables,
19//For example Pair<X,Y>, getX(), getY(), etc.