Search This Blog

Tuesday, June 4, 2013

Sorting the ArrayList by Name and Value in android

Sorting the ArrayList by String comparison by the Following code.

Collections.sort(name, new Comparator<YOURARRAYLISTNAME>() {
    @Override
    public int compare(Invitation lhs, Invitation rhs) {
     return lhs.getName().compareToIgnoreCase(rhs.getName());
    }
   });


You can also compare Arraylist by INTEGER value by following code:


Collections.sort(value, new Comparator<YOURARRAYLISTNAME>() {
    @Override
    public int compare(Invitation lhs, Invitation rhs) {
                        return (lhs.expenditure < rhs.expenditure ? 1 : -1);
    }
   });

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.