• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How is order working in a Collection?

 
Joey Sanchez
Ranch Hand
Posts: 88
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This class is ordered by name but what does it happen when various objects have the same name?



Result:

Which object is the first? Depends on value, hashcode..?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34214
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the original order of the list which affects the order compare to is run. In other words, you shouldn't rely on the order. It isn't guaranteed and future implementations of the JDK could change it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic