• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question wording: sorted but not ordered (?)

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just looking at a mock exam question:
--
Which of the following statements are true?
Select 3 options
1)A LinkedHashMap preserves the order in which objects are added
2)A TreeMap ensures that its elements will be in sorted order
3)Elements in a LinkedList are sorted but not ordered
4)Collections that implement the List interface allow duplicate elements
--

In option 3, what is the difference between "sorted" and "ordered"?

Thanks,
Arthur
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arthur,

Today im also in the same Topic, Let me try to explain you.

For example you are addding the follwing 3 elements: (Ordered)

1. "xxx"
2. "ggg"
3. "ddd"

The above 3 elements will be added (using index value). When you print the elements the output will same as the entry.


Result:
--------
1. "xxx"
2. "ggg"
3. "ddd"


For example you are addding the following 3 elements: (Sorted)

1. "xxx"
2. "ggg"
3. "ddd"

Here you add the elements on the above said, but when you print the output it will be sorted, result will be.

Result
-------
1. "ddd"
2. "ggg"
3. "xxx"

For sorted better remember Telephone index.

Correct me if I'm wrong.

Thanks.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Blair,
When a collection is ordered, it means you can iterate through the collection in a specific order (not-random).ex:-HashTable.
Sorted,a sorted collection means a collection sorted by natural order. And natural order is defined by the class of the objects being sorted (or a supertype of that class, of course).ex:-TreeMap.
NOTE:-There is no Collection that is Sorted and has not Ordered
U can find more information on this from chapter 7 of K&B book.
 
Ponnus Raj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi hanumadeepak muvvala,

"When a collection is ordered, it means you can iterate through the collection in a specific order (not-random).ex:-HashTable."

Hashtable (watchout) Not HashTable

You mean to say that Hashtable is ordered? please clear it..


Thanks.
 
I like tacos! And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic