Collection Interface in Java

Collection Interface in Java


Posted in : Java Posted on : November 24, 2010 at 6:22 PM Comments : [ 0 ]

A collection interface is use to store group of elements or objects. If you want to work with a group of objects in an general manner as possible then use interface.

Collection Interface in Java:

A collection interface is use to store group of elements or objects.  If you want to work with a group of objects in an general manner as possible then use interface. The interface provide some methods for add, manipulate, delete objects in the interface. The all collections implement Collection, so it is important to know its methods. The Collection interface (java.util.Collection) is one of the root interfaces of the Java collection classes. The general methods list of the collection interface is:

boolean add(Object obj)
boolean addAll(Collection c)
void clear( )
boolean contains(Object obj)
boolean containsAll(Collection c)
boolean equals(Object obj)
int hashCode( )
boolean isEmpty( )
Iterator iterator( )
boolean remove(Object obj)
boolean removeAll(Collection c)
boolean retainAll(Collection c)
int size( )
Object[ ] toArray( )
Object[ ] toArray(Object array[ ])

Collection Subtypes: The following interfaces (collection types) extends the Collection interface:

  1.  List

  2.  Set 

  3. SortedSet

  4. NavigableSet

  5. Queue

  6. Deque  

Example :

import java.util.*;
import java.util.Collection;

public class collectioninterface {

public static void main(String[] args) {
Collection collection = new ArrayList();
collection.add("Dev");
collection.add("Manuals");
System.out.print(" Elements Of the Array List are ");
System.out.print(collection + ".");
}
}

Output:

Elements Of the Array List are [Dev, Manuals].

Download This example code

There is more Example for the  methods implementation of this interface.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics