Collections in java is a framework that provides an architecture to store and manipulate the group of objects.
All the operations that you perform on a data such as searching, sorting, insertion, manipulation, deletion etc. can be performed by Java Collections.
Java Collection simply means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet etc).
What is Collection in java
Collection represents a single unit of objects i.e. a group.
What is framework in java
provides readymade architecture.
represents set of classes and interface.
What is Collection framework
Collection framework represents a unified architecture for storing and manipulating group of objects.
Interfaces and its implementations i.e. classes
Hierarchy of Collection Framework
Let us see the hierarchy of collection framework.The java.util package contains all the classes and interfaces for Collection framework.
Methods of Collection interface
There are many methods declared in the Collection interface. They are as follows:
public boolean add(Object element)
is used to insert an element in this collection.
public boolean addAll(Collection c)
is used to insert the specified collection elements in the invoking collection.
public boolean remove(Object element)
is used to delete an element from this collection.
public boolean removeAll(Collection c)
is used to delete all the elements of specified collection from the invoking collection.
public boolean retainAll(Collection c)
is used to delete all the elements of invoking collection except the specified collection.
public int size()
return the total number of elements in the collection.
public void clear()
removes the total no of element from the collection.
public boolean contains(Object element)
is used to search an element.
public boolean containsAll(Collection c)
is used to search the specified collection in this collection.
public Iterator iterator()
returns an iterator.
public Object toArray()
converts collection into array.
public boolean isEmpty()
checks if collection is empty.
public boolean equals(Object element)
matches two collection.
public int hashCode()
returns the hashcode number for collection.
Iterator interface provides the facility of iterating the elements in forward direction only.
Methods of Iterator interface
There are only three methods in the Iterator interface. They are:
public boolean hasNext()
It returns true if iterator has more elements.
public Object next()
It returns the element and moves the cursor pointer to the next element.
public void remove()
It removes the last elements returned by the iterator. It is rarely used.
JavaTpoint (SSS IT Pvt Ltd) provides website development services in affordable cost. We develop websites on WordPress, Core PHP, CakePHP, CodeIgnitor, Open Cart, Servlet-JSP, Struts 2 and Spring technologies. Send us your requirement at firstname.lastname@example.org. We will show you a free demo first, then we will proceed further.
Multivendor E-Commerce (PHP)
Multivendor E-Commerce (Java)
Training For College Campus
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at email@example.com.
Course Fee: ₹ 2000 Per Student
Like/Subscribe us for latest updates or newsletter