aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java.util Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java.util" Watch "java.util" New topic
Author

java.util

geeta rai
Ranch Hand

Joined: Sep 18, 2003
Posts: 48
What is the difference between ordered and sorted?
venkatesh rajmendram
Ranch Hand

Joined: Dec 05, 2000
Posts: 130
In collections can have either ordered or sorted or both...if it is sorted its implicitly ordered ( sort is kind of order) well here is the e.g
When you enter something in a collection say
tom
tim
apple
orange
and when you access it will come in the same order as above.
in case as sorted when you access the collection you will get
apple
orange
tim
tom
I guess that helps
- Venkatesh


SCJP 1.4, SCWCD<p>Ours is a world where people don't know what they want and are willing to go through hell to get it.<br /> - Don Marquis
srini v
Greenhorn

Joined: Dec 15, 2003
Posts: 11
Hi:
Order: as per definition, mean to put things into their proper places in RELATION to each other.
eg., Arrange the given numbers in ascending ORDER
5 2 4 6
Result:
2 4 5 6

Sort: as per definition, a GROUP set up on the basis of any characteristic in common
eg., Sort the following magazines by their catagory.
HBR, PC World, ACM Magazine, BusinessWeek, Fortune
Result:
Business Magazines:HBR, BusinessWeek, Fortune
Computer Magazines: PC World, ACM
Hope this helps.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I have to disagree with srini here; that doesn't make any sense in this context. Venkatesh's explanation is much more accurate. If a collection is ordered, that means that the sequence that the elements occur in is significant. If you're using a List, there's a difference between 1, 2, 3 and 1, 3, 2. If you'r using a Set, there's no difference (or if there is, you should ignore it as unimportant). That's because a List is ordered, and a Set isn't.
Now to sort a List is to put it in a particular order, according to some rule. In the collections framework the rule is always provided by a compareTo() or compare() method, as defined in the Comparable or Comparator interfaces. All sorted collections are also ordered, because if the order wasn't signficant, there's be no point to trying to sort it. But not all ordered collections are sorted.


"I'm not back." - Bill Harding, Twister
srini v
Greenhorn

Joined: Dec 15, 2003
Posts: 11
Dear Jim:
Thanks for your reply.
cheers
 
jQuery in Action, 2nd edition
 
subject: java.util