开发者

Dictionary sort?

开发者 https://www.devze.com 2023-01-24 06:54 出处:网络
hey, i have a dictionnary like \"key2\",\"value2\" \"key3\",\"value3\" \"key1\",\"value1\" is it possible to sort it on va开发者_开发知识库lue ?

hey, i have a dictionnary like "key2","value2" "key3","value3" "key1","value1"

is it possible to sort it on va开发者_开发知识库lue ? If not, any other object can do same thing? (sort value on key/value pair)


Well, clearly you're talking about a Map.

It really depends on what Map you're using, You don't need to sort a TreeMap, coz it is already sorted.

For any other, You can get the keys using map.keySet() and use Collections.sort() to sort them. (Note, the map will remain the same, you'll get a Set containing all the key values)

Hope it helped.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号