Yes, you can use a TreeMap or a ConcurrentSkipListMap, each of which implements SortedMap, and allows you to provide a Comparator at map creation time.
Either implement it as going from Integer as the key, or leave it as a String but supply a comparator that works by converting to Integer and using that for comparison.
I'd have thought it would be cleaner to use Integer as the key, but it won't make much difference.
If you go down the String route, do it like this. It's the same as Huko's code, but doesn't go wrong with large negative values where the difference might cause an overflow.
TreeMap<String, String> map = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return Integer.parseInt(o1).compareTo(Integer.parseInt(o2));
}
});
EDIT: Huko's code now takes this into account too.
TreeMapand provide your ownComparatorthat orders by integer value.