**** Java Certification Training: https://www.edureka.co/java-j2ee-soa-training ****
This Edureka tutorial on “Java Collections” will talk about the complete hierarchy of Collections Frameworks in Java. It will walk you through the various fundamentals of collections like Lists, Queue, Sets, Interfaces etc. Through this tutorial you will learn the following topics:
Java Collection Framework
Collection Framework Hierarchy
Interfaces
List
Queue
Set
Check out our Java Tutorial blog series: https://goo.gl/osrGrS
Check out our complete Youtube playlist here: https://goo.gl/gMFLx3
Java Collections | Collections Framework in Java | Java Tutorial For Beginners | Edureka
1.
2. Topics for Today’s Session
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Collection
Framework
Interfaces Queue
Collection Framework
Hierarchy
List Set
4. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Collection Framework
It provides an architecture to store and manipulate a group of objects
Using Java Collections various operations can be performed on the data like searching,
sorting, insertion, manipulation, deletion, etc.
Java Collection framework provides many interfaces and classes
Collections are the containers that groups multiple items in a single unit
01
02
03
04
9. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Interface
Interfaces are the reference types which are similar to classes but contains only abstract methods
Interface cannot be instantiated
Contains only abstract methods
An interface can extend
multiple interfaces
Interface is implemented by a
class
Interface do not contain
constructors or instance fields
10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Interface
Iterable
The Iterable interface is the root interface for all the collection classes. The Collection interface along with all its
subclasses also implement the Iterable interface.
Methods Iterator<T> iterator()
Collection
Collection interface is implemented by all the classes in the collection framework & declares the methods that every
collection will contain
Methods Boolean add(Object obj)
Iterator The Iterator interface provides the facility of iterating the elements only in a forward direction.
Methods public boolean hasNext() public Object next() public void remove()
Boolean addAll(Object obj) void clear() ...
12. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedListVector
Java List
Java List is an interface that extents the Collection and contains ordered collection of elements including duplicate values
ArrayListList Types
13. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
ArrayList is the implementation of
List Interface where the elements can
be dynamically added or removed
from the list
The size of the list is increased
dynamically if the elements are
added more than the initial size
0 1 2 3 4 5
ArrayList object = new ArrayList ();
14. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
java.utils.ArrayList
boolean add(Collection c)
void add(int index, Object
element)
void clear()
Object[] toArray() void trimToSize()
Object clone()int lastIndexOf(Object o)
15. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Linked List is a sequence of links which
contains items
Linkedlist object = new Linkedlist();
Singly Linked List
Doubly Linked List
Each link contains a connection to another
link
16. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Singly Linked List Doubly Linked List
Each node in this list stores the data of the node and a pointer or reference to the next node in the list
Prev Next Prev Next Prev Next
NULL
HEAD
17. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Singly Linked List Doubly Linked List
Doubly Linked list has two references: one to the next node and another to previous node
Next
NULL
HEAD
NodePrev
NextNodePrev
NextNodePrev
18. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Java.util.Linkedlist
boolean add(Object c) boolean contains(Object o)
void add (int index, Object
element)
int indexOf(Object
element)
int lastIndexOf(Object
element)
void addLast(Object o)void addFirst(Object o)
int size() boolean remove(Object o)
19. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Vectors are similar to arrays, where
the elements of the vector object can
be accessed via an index into the
vector
Vector implements a dynamic array
and is not limited to a specific size
and is synchronized
Vector object = new Vector(size,increment);
0 1 2 3 4 5
20. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
LinkedList
Java List
ArrayList
Vector
Java.util.Vectors
boolean add(Object c)
void add (int index, Object
element)
int indexOf(Object
element)
int lastIndexOf(Object
element)
boolean contains(Object
element)
void clear()
int size() boolean remove(Object o)
22. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Queue
0 1 2 3 … … … n
Insert Remove
Rear Front
Queue in Java follows a FIFO approach i.e. it orders
the elements in First In First Out manner
The first element is removed first and last element
is removed in the end
Queue<Integer> q = new LinkedList<>();
25. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Sets
A Set refers to a collection that cannot contain
duplicate elements
It is mainly used to model the mathematical set
abstraction
LinkedHashSet
TreeSet
HashSet
Set has its implementation in various classes
26. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Sets
LinkedHashSet
TreeSet
HashSet
Java HashSet class creates a collection that use a hash table for storage
Hashset only contain unique elements and it inherits the AbstractSet class and implements Set
interface
It uses a mechanism hashing to store the elements
HashSet<String> al= new HashSet();
27. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Sets
LinkedHashSet
TreeSet
HashSet
Java.util.HashSet
boolean add(Object c) boolean contains(Object o)
Iterator iterator() Object clone()
boolean isEmpty()void clear()
int size() boolean remove(Object o)
28. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Sets
LinkedHashSet
TreeSet
HashSet
Java LinkedHashSet class is a Hash table and Linked list implementation of the set interface
It contains only unique elements
It provides all optional set operations and maintains insertion order
LinkedHashSet<String> al=new LinkedHashSet();
This class inherits methods from other classes
AbstractCollection Object Set
HashSet AbstractSet
29. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Sets
LinkedHashSet
TreeSet
HashSet
TreeSet class implements the Set interface that uses a tree for storage
The objects of this class are unique and are stored in the ascending order
It inherits AbstractSet class and implements NavigableSet interface
TreeSet<String> al=new TreeSet<String>();