java - How to sort ArrayList based on a variables value -


this question has answer here:

i have 1 arraylist<users> users_list; , in users have name, surname, age etc. want implement sorting algorithm sort arraylist based on users age. searched lot found sorting arrays.

use custom java.util.comparator:

public class usercomparator implements comparator<user> {     @override     public int compare(user u1, user u2) {         return u1.getage().compareto(u2.getage());     } } 

and sort like:

collections.sort(users_list, new usercomparator()); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -