Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sorted & Ordered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sorted & Ordered" Watch "Sorted & Ordered" New topic

Sorted & Ordered

Shalini Banerjee

Joined: Dec 06, 2005
Posts: 22
I do not understand what is ment by sorted & ordered of elements.
I am asking the question from Collection Topics.

can any body explain what is the difference between them with example.

thnx in advance.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
When a collection is said to be ordered if it can be iterated in a specific order.
Ex: ArrayList, but a Hashtable is not.

When a collection is said to be sorted if the values in it is sorted in a natural order. So when you are retriving the vaues you get it in sorted order. A sorted collection is also Ordered ..
ex: Treeset
[ December 20, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi Srinivas,

Can u pls elaborate a little bit, more

Siva Prakash
Shaliey Gowtham
Ranch Hand

Joined: Mar 20, 2006
Posts: 104
when you are using the ArrayList and the elements are retrieved in the order in which they are inserted into the list.(ordered but not sorted)

When you use a TreeSet you will have the elements in the specific order
(Eg:Integer objects are sorted in ascending), or in the way you specify

So sorted also means some type of ordering.
But ordering doesnot assure to be sorted.
It is sorta covered in the JavaRanch Style Guide.
subject: Sorted & Ordered