• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Sorted & Ordered

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srinivas,

Can u pls elaborate a little bit, more



Thanks,
Siva Prakash
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The moustache of a titan! The ad of a flea:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic