Map<String,String> map = new TreeMap<String,String>(); map.put("Belorusia", "Minsk"); map.put("Ukraine", "Kiev"); map.put("Russia", "Moskva"); map.put("Iralia", "Rim"); 

treemap to store all values ​​alphabetically, without preserving the order in which the elements were put, but how to sort the map values ​​against the alphabet? I do not remember exactly, but this method was used:

Map<String,String> map = new TreeMap<String,String> (// Here we wrote something, maybe something related to iterable )
When the output card was sorted against the alphabet? What code can be used in brackets?

1 answer 1

 Map<String, String> map = new TreeMap<String, String>(Collections.reverseOrder()); map.put("Belorusia", "Minsk"); map.put("Ukraine", "Kiev"); map.put("Russia", "Moskva"); map.put("Iralia", "Rim"); for(String country : map.keySet()) { System.out.println(country); } 

Conclusion:

 Ukraine Russia Iralia Belorusia