private void handleUserListRequest( WonderlandClientSender sender, WonderlandClientID clientID, UserListRequestMessage message) { UserList out = new UserList(); for (User user : users.values()) { out.getUsers().add(user); } Collections.sort( out.getUsers(), new Comparator<User>() { public int compare(User t, User t1) { // first compare names int res = t.name.compareTo(t1.name); if (res == 0) { // compare dates if the names are equal res = t.when.compareTo(t1.when); } return res; } }); sender.send(clientID, new UserListResponseMessage(message.getMessageID(), out)); }