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
Post a Comment