(a)Smack Sort HostedRoom Collection Alphabetically

So i can get hosted rooms nicely, but when listing them using their names it is a little disorganized. So i am trying to sort by the HostedRoom.GetName() needless to say i can’t figure out how to do it. Heh…

here is an example of my attempt.

(Getiing error

The method sort(List, Comparator<? super T>) in the type Collections is not applicable for the arguments (Collection, RoomList.CustomComparator)

under sort)

Collection rooms = null;

try {

rooms = MultiUserChat.getHostedRooms(GlobalVar.mConnection, “conference.”+GlobalVar.mConnection.getServiceName());

} catch (XMPPException | NoResponseException | NotConnectedException e) {

e.printStackTrace();

}

Collections.sort(rooms, new CustomComparator());

class CustomComparator implements Comparator {

@Override

public int compare(HostedRoom o1, HostedRoom o2) {

return o1.getName().compareTo(o2.getName());

}

}

Collection is not a subclass of List.

Well that would explain why i can’t do that… hmm… Any way to sort it Alphabetically?

was thinking of iterating through the list and populating another list if the iterator began with an “a” then flipping and redoing it except it would be “b” until all elements were removed from the first list.

You can easily create a list out of a collection. BTW in a feature version of Smack getHostedRooms will return a List instead of a collection. Thanks for reporting this.

Awesome! Glad I could help I’ll transform the collection to a list and then sort the list. When I have finished doing so I’ll edit this with the code to do so. In case anyone else comes along (before you update it).