Java ArrayList clear Example

ArrayList class clear method example. This example shows you how to use clear method.


ArrayList class clear method example.public void clear() Removes all of the elements from this list. The list will be empty after this call returns.

Here is the code

/**
 * @ # Clear.java
 * A class repersenting use to clear() method of ArrayList class in java.util package
 * version 14 May 2008
 * author Rose India 
 */
import java.util.*;

public class Clear {

    public static void main(String args[]) {
        List arrlist = new ArrayList();
        int i = 0;
        String str = "Rose India";

        //Add the specified element to the end of this list.
        arrlist.add(i);
        arrlist.add(str);
        System.out.println("arrlist = " + arrlist);

        //Removes all of the elements from this list.
        arrlist.clear();
        System.out.println("arrlist = " + arrlist);
    }
}

Output
arrlist = [0, Rose India]
arrlist = []

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US