permaculture playing cards*
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 Murach's Java Servlets and JSP this week in the Servlets 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

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?


Which object is the first? Depends on value, hashcode..?
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30068

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
subject: How is order working in a Collection?
Similar Threads
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