This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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

java.util

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between ordered and sorted?
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
srini v
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Jim:
Thanks for your reply.
cheers
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic