This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
An ordered collection maintains a specific order. It doesn't have to be sorted, there's just some notion of an order - often based on the order things are added to it. So an ArrayList is ordered. A LinkedHashSet is ordered. A HashSet isn't - there is no concept of an order, and if you iterate through it you aren't guaranteed to get the same order every time.
A sorted collection is a special case of an ordered collection where the order is determined by the values. An ArrayList isn't sorted (unless you sort it yourself), but a TreeSet is.
Vishal Hegde wrote:lease provide me an example for the same so that it will be easy for me to differntiate the difference between ordered and Sort
I believe Matthew already did. Sorted collections (like TreeSet) maintain their elements in a predetermined sorted sequence, defined either by a Comparator or - when elements are Comparable - by their natural order. Ordered collections have a predictable order, but it's usually (as Matthew said) based on the order they were added.
What else don't you understand?
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
1 ,2,3,4,5,6,7,8,9, they are in Order right and sorted in ascending Order or
A,B,C,D,E,G,H etc is also ordered right and also sorted in ascending order . . .
You can’t tell whether those are ordered.
If you created the first series like this: add(1) add(9) add(2) add(8) add(3) add(7) add(4) add(6) add(5), then they are out of order.
“Sorted” is a word with a precise meaning, but “ordered” isn’t. By saying ordered you usually mean in the same order that elements were inserted. But you can insert elements into a List in locations earlier than elements already in the list, eg using add(1, E);
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Collection framework doubt , what is the difference between Ordering and Sorting