public static void main(String[] args) { Mapmap = new TreeMap (); map.put("d", "ddddd"); map.put("c", "ccccc"); List > list = new ArrayList >(map.entrySet()); Collections.sort(list, new Comparator >() { public int compare(Map.Entry o1, Map.Entry o2) { return o1.getKey().compareTo(o2.getKey()); } }); String string = String.valueOf(list.get(0)) + String.valueOf(list.get(1)); System.out.println(string); }