Professional Documents
Culture Documents
INTERFACE IN
JAVA
What is Collections Framework?
•A Collection represents a group of objects. The Collections Framework
provides the functionality to manage collections and always represents a
combined architecture for storing the objects.
Interfaces: Interface in Java refers to the abstract data types. They allow Java
collections to be manipulated independently from the details of their
representation.
Syntax:
ArrayList object = new ArrayList ();
LinkedList Class
•LinkedList implements the List interface which allows storing the duplicate
elements.
•Uses a doubly linked list data structure to store elements.
•Maintains the insertion order.
•LinkedList is not synchronized and its manipulation is fast because no
shifting is required.
Syntax:
LinkedList obj= new LinkedList();
Vector Class
Syntax:
Vector object = new Vector(size ,
increment);
Stack Class
Syntax:
Stack obj= new Stack();
The Set Interface
•A Set refers to a collection that cannot contain duplicate elements . It is a
generic interface that extends the Collection interface.
•Set is Immutable.
•Ability to compare the contents of two sets accurately.
• Set has its implementation in various classes such as HashSet, TreeSet and
LinkedHashSet.
HashSet class
TreeSet class
TreeSet class implements the Set interface that uses a tree for storage. The objects
of this class are stored in the ascending order. Also, it inherits AbstractSet class
and implements NavigableSet interface. It contains only unique elements like
HashSet. In TreeSet class, access and retrieval time are faster.
The Queue Interface
•The Queue interface provides the functionality to add, remove,
access, and examine the queue elements. Typically, queues implement
a First-In-First-Out(FIFO) behaviour. The Dequeue interface extends
the Queue interface to support double-ended queues.
ArrayList Vector
1) ArrayList internally uses a dynamic array to LinkedList internally uses a doubly linked list to
store the elements. store the elements.
3) An ArrayList class can act as a list only LinkedList class can act as a list and queue both
because it implements List only. because it implements List and Deque interfaces.