Like the next Map object:
Hashmap<integer, string> map = new Hashmap<integer, string> ();
Map.put (3, "A");
Map.put (2, "B");
Map.put (1, "C");
The first method of ordering key values:
object[] key = Map.keyset (). ToArray (); Arrays.sort (key); for (int0; i<key.length; i++) { log.i ("sang" " value=>"+map. Get (Key[i])); }
Key-Value ordering the second method:
List arrayList =NewArrayList (Map.entryset ()); Collections.sort (ArrayList,NewComparator () { Public intCompare (object Arg1, Object arg2) {map.entry obj1=(map.entry) arg1; Map.entry Obj2=(map.entry) arg2; return(Obj1.getkey ()). ToString (). CompareTo (Obj2.getkey ()); }});//sort the data in the HashMap for(Iterator iter =arraylist.iterator (); Iter.hasnext ();) {Map.entry Entry=(Map.entry) iter.next (); String Key=(String) Entry.getkey (); LOG.I ("sang","value ="+map.Get(key)); }
Android HashMap two ways to sort by key value