File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: Sorted & Ordered
It's not a secret anymore!