fork download
  1. import java.util.Map;
  2. import java.util.SortedMap;
  3. import java.util.TreeMap;
  4.  
  5. class Idiom112
  6. {
  7. public static void main (String[] args)
  8. {
  9. SortedMap<Integer, String> mymap = new TreeMap<>();
  10. mymap.put(5, "five");
  11. mymap.put(2, "two");
  12. mymap.put(8, "eight");
  13. mymap.put(6, "six");
  14. mymap.put(1, "one");
  15.  
  16. for(Map.Entry<Integer, String> e: mymap.entrySet())
  17. System.out.println("Key=" + e.getKey() + ", Value=" + e.getValue());
  18. }
  19. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Key=1, Value=one
Key=2, Value=two
Key=5, Value=five
Key=6, Value=six
Key=8, Value=eight