Generally we have Collection implementations like ArrayList, Vector, HashSet...etc.
But we have four kind of collections ...
1) Ordered Collection
2) UnOrdered Collection
3) Sorted Collection
4) UnSorted Collection
If we know what is Ordered and Sorted collection, We can understand all the above 4 collections.
Ordered Collection:
When a Collection is ordered, It means you can iterate through the collection in a specific (not-random) order.
- A HashTable collection is not ordered.
- An ArrayList keeps the order established by the element's index position.
- LinkedHashSet keeps the order established by insertion, so the last element inserted is the last element in the LinkedHashSet.
- Some collections that keep an order referred to as the natural order of the elements, and those collections are then not just ordered, but also sorted.
collection implementations order properties:
TreeMap - Sorted
LinkedHashMap - By insertion order or last access order.
TreeSet - Sorted
LinkedHashSet - By insertion order
ArrayList - By index
Vector - By index
LinkedList - By index
Sorted Collection:
The order in the collection is determined according to some rule or rules, known as the sort order.
Sorting is done based on properties will figure out what order to put them in, based on the sort order.
Most commonly, the sort order used is something called the natural order.
collection implementations order properties:
TreeMap - By natural order or custom comparison rules
TreeSet - By natural order or custom comparison rules
No comments:
Post a Comment