Collection in Java 

  •  Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.
  • Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.
  • Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes(yet to study).

Framework in Java

  • It provides readymade architecture.
  • It represents a set of classes and interfaces.
  • It is optional.(need to ask trainer).

The Collection framework represents a unified architecture for storing and manipulating a group of objects. It has:

  1. Interfaces and its implementations, i.e., classes
  2. Algorithm
o.MethodDescription
1public boolean add(E e)It is used to insert an element in this collection.
2public boolean addAll(Collection<? extends E> c)It is used to insert the specified collection elements in the invoking collection.
3public boolean remove(Object element)It is used to delete an element from the collection.
4public boolean removeAll(Collection<?> c)It is used to delete all the elements of the specified collection from the invoking collection.
5default boolean removeIf(Predicate<? super E> filter)It is used to delete all the elements of the collection that satisfy the specified predicate.(to be discussed)
6public boolean retainAll(Collection<?> c)It is used to delete all the elements of invoking collection except the specified collection.
7public int size()It returns the total number of elements in the collection.
8public void clear()It removes the total number of elements from the collection.
9public boolean contains(Object element)It is used to search an element.
10public boolean containsAll(Collection<?> c)It is used to search the specified collection in the collection.
11public Iterator iterator()It returns an iterator.(will learn later)
12public Object[] toArray()It converts collection into array.
13public <T> T[] toArray(T[] a)It converts collection into array. Here, the runtime type of the returned array is that of the specified array.(to ask trainer)
14public boolean isEmpty()It checks if collection is empty.
15default Stream<E> parallelStream()It returns a possibly parallel Stream with the collection as its source.(later will discuss)
16default Stream<E> stream()It returns a sequential Stream with the collection as its source. (later will discuss)
17default Spliterator<E> spliterator()It generates a Spliterator over the specified elements in the collection. (later will discuss)
18public boolean equals(Object element)It matches two collections.
19public int hashCode()It returns the hash code number of the collection.

Reference:https://www.javatpoint.com/collections-in-java

Leave a comment

Design a site like this with WordPress.com
Get started