Look into using a TreeMap instead, which will sort the elements you add to it in ascending order based on the Integer key automatically.
TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>();
treeMap.add(1, "foo");
treeMap.add(3, "baz");
treeMap.add(2, "bar");
Iterating over this TreeMap in order of ascending integer keys will print "foo bar baz".