0

Here i'm able to get User Screen names and printing with the below code,but how can i sort those name alphabatically.

Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
String name = (String) request.getSession().getAttribute("name");
long cursor = -1;
IDs ids = twitter.getFollowersIDs(name, cursor);
do {
    for (long id : ids.getIDs()) {
        User user = twitter.showUser(id);
        out.println(user.getName());
    }
} while ((cursor = ids.getNextCursor()) != 0);

This is my code where i'm getting names,how can i sort names.Thank for your help.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
tajMahal
  • 418
  • 6
  • 18
  • 40
  • possible duplicate of [Sort ArrayList of custom Objects by property](http://stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property) – Jonathan Jun 10 '14 at 13:37
  • Sorry@Jonathan,I'm unable to get it,could you please tell me how to sort those names? – tajMahal Jun 10 '14 at 13:39
  • Apologies on reflection that question I highlighted may not be appropriate. I was still thinking about your [previous question](http://stackoverflow.com/q/24135504/69875) where you had a `ResponseList` to deal with! – Jonathan Jun 10 '14 at 14:46

1 Answers1

0

Actually a Comparator may be more than you need, I got mixed up with your previous question.

You can simply collect the names themselves in a list and then sort, e.g.:

...
final List<String> names = new LinkedList<String>();
do {
    for (...) {
        ...
        names.add(user.getName());
    }
} while (...);

Collections.sort(names) 

If you inspect names, it will now be sorted.

Community
  • 1
  • 1
Jonathan
  • 20,053
  • 6
  • 63
  • 70