The Collection in Java Is A Framewo
The Collection in Java Is A Framewo
Java Collections can achieve all the operations that you perform on a data such as
searching, sorting, insertion, manipulation, and deletion.
Iterable
|
collection
| | | |
List Queue Set Map
|
ArrayList | -->PriorityQueue ->HashSet -->Hash
Map
|
LinkedList Deque ->LinkedHashSet -->
LinkedHashMap
|
Vector ->ArrayDeque | |
|
Stack SortedSet
SortedMap
| |
treeSet
treeMap
Iterator Interface:
Iterator interface provide facility to iterate elements in forward direction only
hasNext(), next()
PriorityQueue Class:
-------------------
PriorityQueue is also class that is defined in the collection framework that gives
us a way for processing the objects on the basis of priority. It is already
described that the insertion and deletion of objects follows FIFO pattern in the
Java queue. However, sometimes the elements of the queue are needed to be processed
according to the priority, that's where a PriorityQueue comes into action.
Set Interface:
-------------
Set Interface in Java is present in java.util package. It extends the Collection
interface. It represents the unordered set of elements which doesn't allow us to
store the duplicate items. We can store at most one null value in Set. Set is
implemented by HashSet, LinkedHashSet, and TreeSet.
HashSet class:
-------------
1. HashSet stores the elements by using a mechanism called hashing.
2. HashSet contains unique elements only.
3. HashSet allows null value.
4. HashSet class is non synchronized.
5. HashSet doesn't maintain the insertion order. Here, elements are inserted on the
basis of their hashcode.
6. HashSet is the best approach for search operations.
The initial default capacity of HashSet is 16, and the load factor is 0.75.
SortedSet Interface:
-------------------
SortedSet is the alternate of Set interface that provides a total ordering on its
elements. The elements of the SortedSet are arranged in the increasing (ascending)
order. The SortedSet provides the additional methods that inhibit the natural
ordering of the elements.
positive integer, if the current object is greater than the specified object.
negative integer, if the current object is less than the specified object.
zero, if the current object is equal to the specified object.
It provides multiple sorting sequences, i.e., you can sort the elements on the
basis of any data member, for example, rollno, name, age or anything else.