Tuesday, 30 January 2018

Collection in java

Collections in java is a framework that provides an architecture to store and manipulate the group of objects. Collection is use to represent a group of individual object in java.

What is Collection Framework In Java?

Collection Framework in java is a centralized and unified theme to store and manipulate the group of objects. Java Collection Framework provides some pre-defined classes and interfaces to handle the group of objects. Using collection framework, you can store the objects as a list or as a set or as a queue or as a map and perform operations like adding an object or removing an object or sorting the objects without much hard work.

Collections Framework hierarchy




Methods of Collection interface

Collection interface contains total 15 abstract methods. 14 of it’s own and one is inherited from Iterable interface. Here is the list and descriptions of those methods.

No.
Method
                         Description
       1
public boolean add(Object element)
is used to insert an element in this 
collection.
      2
public boolean addAll(Collection c)
is used to insert the specified collection 
elements in the invoking collection.
      3
public boolean remove(Object element)
is used to delete an element from this 
collection.
     4
public boolean removeAll(Collection c)
is used to delete all the elements of 
specified collection from the invoking
 collection.
     5
public boolean retainAll(Collection c)
is used to delete all the elements of 
invoking collection except the specified 
 collection.
     6
public int size()
return the total number of elements in 
the collection.
     7
public void clear()
removes the total no of element from 
the collection.
     8
public boolean contains(Object element)
is used to search an element.
     9
public boolean containsAll(Collection c)
is used to search the specified collection 
in this collection.
    10
public Iterator iterator()
returns an iterator.
    11
public Object[] toArray()
converts collection into array.
     12
public boolean isEmpty()
checks if collection is empty.
    13
public boolean equals(Object element)
matches two collection.
    14
public int hashCode()
returns the hashcode number for 
collection.








































We will learn following topic in Java Collections Framework

  1.       List interface
  2.       Cursors in java






DashZin

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

7 comments: