Let Us Know About Collection FrameWork In Java


This resource contains the information about collection FrameWork in java like HashTable, ArrayList, LinkedList, Vector, HashSet, TreeSet, Collection type etc.

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.

Collection type:- collection

List:
ArrayList
LinkedList
Vector

Set:
LinkedHashSet
HashSet
TreeSet

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.

ArrayListExample.java
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.

MyStack.java
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.

VectorExample.java
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.

HashSetExample.java
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.

TreeSetExample.java
It stores data in ascending order. add() adds data to TreeSet object remove() takes data and removes from TreeSet object.

Note:
HashSet , TreeSet are dynamic object arrays.

Map:
These interface family classes maintain key-value pairs of data.
Key should not be duplicated. Value can be duplicated.
Example: HashTable.

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.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: