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

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -