Collection Interface

Collection Interface –
    Collection Interface has arranged on top of the Collection Framework because any class within the Collection Framework must be implement.
    Collection Interface also extends Iterable Interface so that any class can have use for-each loop for iterating the objects from Collection Interface.
    Declaration of Collection Interface is :
    interface Collection<E>
   
    E denotes the data type of the objects which will store with in the Collection Interface
Now we are providing the Methods List with description which is framed in Collection Interface.

boolean add(Object obj) –

This method is used for add news object in the Collection. This method returns false if Collection has this object already otherwise this method add the objects and return true.

boolean addAll(Collection c) –
    This method adds all the object of Collection c and return true, otherwise return false in case of failure.

void clear() –
    This method is used for remove all element from the Collection. Return type of this method is void means nothing will be return.

boolean contains(Object obj) –
    This method is used for check the availability of given object within the collection. If this method return true means object is available otherwise this method will return false.

boolean containsAll(Collection c) –
    This method is used for check the all elements of given Collection are available or not within the collection. If this method return true means all objects are available otherwise this method will return false.

boolean equals(Object obj) –
    This method is used for check the given object are equals with collection. If both are equals, return true otherwise return false.

int hashCode() –
This method is used for rehashing mechanism*. This method gives the hash code of collection.

boolean isEmpty() –
     This method is used for checking the collection has element or not. This method return false means there is no element in the collection otherwise return true.

Iterator<E> iterator() -
    This method is used for iterate the objects form collection.  E denoted the type of object which is within the collection.

boolean remove(Object obj) –
    This method is used for remove the given object from the collection. If this method return true means obj has removed otherwise this method will return false.


boolean removeAll(Collection c) -
      This method is used for remove all object of given collection c from the collection. If this method return true means all objects have removed otherwise this method will return false.

boolean retainAll(Collection c) –
    This method is used for removing all elements from collection except given element of collection c. This method also return boolean, true or false according to work done.

int Size() –
    This method is used for knowing how many element are in the collection. It returns int value.

Object[ ] toArray() –
    This method is used for convert collection to array of Objects which is placed in the collection.

Object[ ] toArray(Object obj[]) –
    This method returns the array of object which is passed within the parameter and all element of collection is copied within this array of objects. This method gives an ArrayStoreException in case the data type miss match.

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Use of req.query, req.params and req.body in NODE JS

How to capture finger prints in java