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"?
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.
posted 14 years ago
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..
Raj<br /><b>SCJP 1.4</b>
Men call me Jim. Women look past me to this tiny ad: