The Official Programming Thread

XxRebellionxX

Moderator
Moderator
Mar 10, 2010
6,132
0
42
Dublin
Which name is being used for the sort? I'm assuming it's using the surname. You really should have your own comparator for this situation. In your comparator decide the order based on the last name, in case if both the last names are the same then decide on the first name; if the first names are the same too then retain their order in the sorted list. Such a comparator will give you a correct output.
So its absolutely necessary to use the comparator, it can't be done without it?
Is it possible to convert the Set to ArrayList and then use Collections.sort?
 

Newton

Well-known member
May 17, 2009
2,224
0
41
Lahore, Faisalabad
So its absolutely necessary to use the comparator, it can't be done without it?
Is it possible to convert the Set to ArrayList and then use Collections.sort?
even in that case, it will sort based on the default comparison. It won't handle custom cases where the value being sorted upon is the same for 2 or more elements.
 
General chit-chat
Help Users
Bugs, Issues, Feature Requests ▶ GO here ◀
  • No one is chatting at the moment.
    iampasha iampasha: https://www.digitaltrends.com/gaming/ps5-xbox-seris-x-pc-comparison/ rip peeeCeee finally dead...