File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How is order working in a Collection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How is order working in a Collection?" Watch "How is order working in a Collection?" New topic
Author

How is order working in a Collection?

Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86

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

Joined: May 26, 2003
Posts: 30752
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How is order working in a Collection?