my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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?
 
Similar Threads
HashMap
Set that only Items can be added
print m1 m2 m3 in 3 different threads in sequence
Mock question from SCJP book
Problem with using variable before it is defined