android - Sort ArrayList with hashmap with int values -
i have arraylist contains hashmaps several key/value pairs. 1 of key/value pairs contains key "order" , value int. how can sort arraylist according "order" key of hashmaps contains please? (i can string value not int value)
something it:
list<map<string, integer>> list = new arraylist<map<string, integer>>(); collections.sort(list, new comparator<map<string, integer>>() { final static string compare_key = "order"; @override public int compare(map<string, integer> lhs, map<string, integer> rhs) { integer v1 = lhs.get(compare_key); integer v2 = rhs.get(compare_key); return v1 < v2 ? -1 : v1 > v2 ? 1 : 0; } });
Comments
Post a Comment