Let Us Know About Collection FrameWork In Java
Collection FrameWork is used to maintain data structures. java.util package is imported for collection framework classes and interfaces.
List interface family classes are used to store dynamic objects. That means those are dynamic object arrays. LinkedList class is used to implement stack, queue. Vector, ArrayList is used to maintain dynamic object array. ArrayList is not synchronised. That means multiple threads can operate ArrayList object in sharing mode. Vector is synchronized. That means only one thread can operate this object at a time. List interface family classes can support duplicate values.
Itssize() method returns count of values of ArrayList object. Its one argument add() method adds data to ArrayList object. Its two arguments add() method takes index, value and inserts that value at given index. remove () method takes index or data and removes that index position value or data.
Below are the methods of LinkedList class:-
addFirst() adds data at first place of LinkedList object.
addLast() adds data at last place of LinkedList object.
getFirst() returns one copy of first place data.
removeFirst() removes first place data after returning it.
getLast() returns one copy of last place data.
removeLast() removes last place data after returning it.
Below are the methods of Vector class:-
add() method adds data to Vector class object.
iterator() method creates iterator class object and initializes that object with Vector object data.
Below methods are of Iterator class:-
hasNext() returns true when data is pointed out . Otherwise HashSet, TreeSet e false.
next() returns data which are pointed out.
A set interface family class does not support duplicate values.
Below are the methods of HashSet class:-
add() adds data to HashSet object
remove() takes data and removes from HashSet object. It does not sort data.
It stores data in ascending order. add() adds data to TreeSet object remove() takes data and removes from TreeSet object.
HashSet , TreeSet are dynamic object arrays.
These interface family classes maintain key-value pairs of data.
Key should not be duplicated. Value can be duplicated.
Below are the methods of HashTable class:-
Its put() stores key, value pair of data in the HashTable .
Its keys() method returns key information as Enumeration object.
get() method takes key and returns its value from HashTable object.
Below are the methods of Enumeration:-
hasMoreElements() method returns true when data is pointed out .
Otherwise returns false.
nextElement() returns data which are pointed out. But this data is as Object class type. It is type of caste to String type.