Am trying to sort via a certain value in the function,
Collection users = roster.getEntries();
if(!users.isEmpty()) {
Iterator userIterator = users.iterator();
while(userIterator.hasNext()) {
String name = user.getName()==null?user.getUser():user.getName();
Now before iterating, I want to sort this Collection by the user’s name. Any suggestions on how to go about this?
Thank you for your time.
You can use Collections.sort() and provide a Comparator, provided the collection preserves order. If it doesn’t copy it into an ArrayList.
Unless you are using Java 1.4 or older I would use generics and the for-each loop.