410   Java

list for examle

[
    {
        name:'one',
        value:'1'
    },
    {
        name:'four',
        value:'4'
    },
    {
        name:'three',
        value:'2'
    },
    {
        name:'three',
        value:'3'
    },
]


sort by value

// function for list to sort

	log.info("list:"+list.toString());

	Collections.sort(list, new Comparator<HashMap>() {  
	@Override
        public int compare(HashMap o1, HashMap o2) {				
                int hits0 = Integer.parseInt(o1.getValue.toString());  
                int hits1 = Integer.parseInt(o2.getValue.toString());  
                if (hits1 > hits0) {  
                    return 1;  
                } else if (hits1 == hits0) {  
                    return 0;  
                } else {  
                    return -1;  
                }  
	}  
        }); 
	log.info("After sort list:"+list.toString());





Leave a Reply

Your email address will not be published. Required fields are marked *