Search code examples
javadictionaryoophashmap

How to get value from map of Pair and Object in java


I want to return map value by using position which is the key of the map I have this function :

Map<Pair<Integer , Integer> , Unit> map = new HashMap<>();
public Unit getUnit(Pair<Integer , Integer> position){
    return map;
}

Solution

  • You'd get the value like you would with any other key, using Map.get:

    public Unit getUnit(Pair<Integer, Integer> position) {
        return map.get(position);
    }