How to sort a key of a map
Posted
by
Tsuna Sawada
on Stack Overflow
See other posts from Stack Overflow
or by Tsuna Sawada
Published on 2011-01-06T05:31:59Z
Indexed on
2011/01/06
5:54 UTC
Read the original article
Hit count: 274
How to sort (any kind of sorting) a key of a map(treemap or hashmap)
i have a problem and it goes like this.
i have a map that has a key of
27527-683,
27525-1179,
27525-1571,
27525-1813,
27525-4911,
27526-1303,
27526-3641,
27525-3989,
27525-4083,
27525-4670,
27526-4102,
27526-558,
27527-2411,
27527-4342
this is the list of keys and the value for each of the key is a list.
now, how can i sort this key in ascending order by number.
ex. if i want to sort : 1,2,11,20,31,3,10
i want to have as output is : 1,2,3,10,11,20,31
but when i use the autosort of treemap the output goes : 1,10,11,2,20,3,31
how can i sort it in ascending order by numeric?
please help me. i can't think of anymore ways because this is my first time handling map and list
© Stack Overflow or respective owner