java - How to sort ArrayList based on a variables value -
this question has answer here:
- sort arraylist of custom objects property 23 answers
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
Post a Comment