Collection Interface clear() Method

Collection Interface clear() Method


Posted in : Java Posted on : November 24, 2010 at 7:05 PM Comments : [ 0 ]

This method are used to remove all elements from the invoking collection.

Collection Interface clear() Method:

This method are used to remove all elements from the invoking collection.

Syntax :

void clear();

Example :

import java.util.*;

public class CollectionInterfaceClearMethodExample {
 public static void main(String[] args) {
  Collection collection = new ArrayList();
  collection.add(1);
  collection.add(2);
  collection.add(3);
  System.out.print("Elements of the Array List before use of clear method ");
  System.out.println(collection + ".");
  collection.clear();
  System.out.print("Elements of the Array List after use of clear method ");
  System.out.println(collection + ".");
 }
}

Output :

Elements of the Array List before use of clear method [1, 2, 3].
Elements of the Array List after use of clear method [].

Download This example code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics