Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to Order ArrayList<HashMap<String,String>>?

I'm saving details of product in a map and adding in ArrayList< HashMap< String,String >> and setting in to a custom list adapter. I need to sort the values by price in it. How to achieve it? Thanks in advance.

like image 559
Pattabi Raman Avatar asked Nov 28 '22 11:11

Pattabi Raman


1 Answers

Pleas use the code below :

ArrayList< HashMap< String,String >> arrayList=populateArrayList();
    Collections.sort(arrayList, new Comparator<HashMap< String,String >>() {

        @Override
        public int compare(HashMap<String, String> lhs,
                HashMap<String, String> rhs) {
            // Do your comparison logic here and retrn accordingly.
            return 0;
        }
    });
like image 52
Eldhose M Babu Avatar answered Nov 30 '22 00:11

Eldhose M Babu