Answers for "java arraylist of pairs"

0

java arraylist of pairs

List<Pair<Integer,String>> pairList = new ArrayList<Pair<Integer,String>>();

public class Pair<Key,Value> {
    private Key key;
    private Value value;

    public Pair(Key key, Value value){
        this.key = key;
        this.value = value;
    }

    public Key getKey(){ return this.key; }
    public Value getValue(){ return this.value; }

    public void setKey(Key key){ this.key = key; }
    public void setValue(Value value){ this.value = value; }
}
//Notice that it doesn't have to be in a "Key-Value" fashion, it can be any 2 variables,
//For example Pair<X,Y>, getX(), getY(), etc.
Posted by: Guest on January-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language