I have a List
of HashMap
such as below
ArrayList l = new ArrayList ();
HashMap m = new HashMap ();
m.add("site_code","AL");
m.add("site_name","Apple");
l.add(m);
m = new HashMap();
m.add("site_code","JL");
m.add("site_name","Cat");
l.add(m);
m = new HashMap();
m.add("site_code","PL");
m.add("site_name","Banana");
l.add(m)
I'd like to sort the list
based on site_name
. So in the end it would be sorted as.
Apple, Banana, Cat
I was trying something like this:
Collections.sort(l, new Comparator(){
public int compare(HashMap one, HashMap two) {
//what goes here?
}
});