So I'm trying to get the key of a TreeMap by an int index.
Here's my code:
TreeMap<String, Integer> map = new TreeMap<String, Integer>(Collections.reverseOrder());
map.put("hi", 1);
map.put("hi2", 5);
System.out.println("Key: " + (String) map.keySet().toArray()[0] + "\nValue: " + map.get(0));
But when I execute this, I get the error:
java.lang.Integer cannot be cast to java.lang.String
So I'm trying to get the key: "hi2"