I would like to sort my hashmap by key so that it prints out letters first and then numbers i.e a,b,c,d,1,2,3,10,100.
Is there a smart way to do this?
public static void main(String[] args) throws IOException {
HashMap<String, Integer> values = new HashMap<String, Integer>();
values.put("A",1);
values.put("B",2);
values.put("C",3);
values.put("D",4);
values.put("1",5);
values.put("2",6);
values.put("3",7);
values.put("10",8);
values.put("100",9);
SortedSet<String> sortedset= new TreeSet<String>(values.keySet());
Iterator<String> keys = sortedset.iterator();
while(keys.hasNext()){
System.out.println(values.get(keys.next()));
}
}
Thanks