• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to sort by both comparator arguments?  RSS feed

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'd like to sort by Unit id first (where Unit has an id which is an Integer), then sort by the String value
The String values have the format of 0:0:0 where 0s are integers.
Thanks
Jack
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should have a class with the iD and the other value as fields.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the key of the map is unrelated to the id of the unit, then you can't do this with your map. You should use different keys, or sort your values at a later stage.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:If the key of the map is unrelated to the id of the unit, then you can't do this with your map. You should use different keys, or sort your values at a later stage.


Got it, thanks... I'll try the other way round.
Jack
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!