Tuesday, November 15, 2011

Sorting an Array and ArrayList in Android

 Sorting an ArrayList  in Android 
in this method for sorting names or contact list in alphabetical order

ArrayList<User> res = new ArrayList<User>();
res.add(…);
res.add(…);
Comparator<User> comperator = new Comparator<User>() {
@Override
public int compare(User object1, User object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Collections.sort(res, comperator);


Sorting an Array in Android


User[] res = new User[];
res.add(…);
res.add(…);
Comparator<User> comperator = new Comparator<User>() {
@Override
public int compare(User object1, User object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Array.sort(res, comperator);

1 comment:

  1. Most essential drugs are offered free of charge in these hospitals. However, the fact that the government sector is understaffed,

    ReplyDelete

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...