Ok so I have an online game and for each connection the server program creates a “user object.” I would like to be able to arrange these user objects in a list (or arraylist or vector etc…) by alphabetical order by username. I know sorting would be easy if these were just strings but the user objects encapsulate other data besides the username. I know it would be possible to traverse the list in a for loop and then compare each username character by character but it seems like this is highly inefficient.
Anyone know of an easier way?
I looked at using Collections.sort(list); but in order for this to work there has to be a “natural ordering” of my user objects. How do you specify the natural ordering?