I am using the Facebook SDK for Android to pull a list of a given user’s friends. The problem is that the friends are sorted by userid (useless to the end-user). I need them sorted alphabetically.
Currently, I have the list in a JSONArray, and I’m wondering what sort of data structure I should put the names into in order to achieve optimal sorting. So we need to consider insertion time, sort time, and fetch time.
From reading other similar situations online, I am currently leaning towards a TreeSet, but that is just a hunch. What do you all think?
I would use
TreeSet, but not for performance reasons.TreeSetimplementsSortedSetso you have you user list always sorted with right comparator given.And
Setalso makes it easy to update: Just put all new Users into the set regardless they are already in or not. Sets do not contain duplicates.I would not think a second about performance here since nobody will have such huge friendslists that it makes a difference.