• Post Reply Bookmark Topic Watch Topic
  • New Topic

How is order working in a Collection?  RSS feed

 
Joey Sanchez
Ranch Hand
Posts: 92
Java Linux Netbeans IDE
  • 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: 37181
515
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
Boost this thread!