java - Sort map by key string (where key is actually an integer) -


i trying sort map show in dropdown. not able sorting done. return new map. not map sorted key expect.

private map<string, string> mapinstrumentids = new treemap<>();  map<object, object> val = mapinstrumentids                     .entryset()                     .stream()                     .sorted(map.entry.comparingbykey())                     .collect(collectors.tomap(map.entry::getkey, map.entry::getvalue)); 

i of course didn't think key integer. means sorting string not give me expected result (as integer sort). changing key integer , converting value yield expected result.

by default treemap guarantees elements sorted in ascending key order.


Comments

Popular posts from this blog

c - Calling a function within a loop -

vb.net - Unbound DataGridView add row with checkbox error -

How i fill combobox items in Radgridview manually using in vb.net -