I have to take the input of some integer pairs. After that sort them and I've to do some arithmetic operation with the pair.
I used TreeMap
as it allows sorting too but it fails when I have the duplicate key.
So, what collection/method should I use in my program? Please suggest.
TreeMap<Integer, Integer> h = new TreeMap<Integer, Integer>(Collections.reverseOrder());
for(int i=0; i<n; i++){
String ll[] = br.readLine().split(" ");
h.put(Integer.parseInt(ll[0]), Integer.parseInt(ll[1]));
}