File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorted & Ordered

 
Shalini Banerjee
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
siva prakash
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivas,

Can u pls elaborate a little bit, more



Thanks,
Siva Prakash
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic