Friday 30 May 2014

ArrayList : clear : Clear the Elements in LinkedList

public void clear()
Removes all of the elements from this list.

import java.util.*;

class ArrayListClear{
 public static void main(String args[]){
  ArrayList<Integer> myList;
  myList = new ArrayList<Integer> ();
  
  myList.add(10);
  myList.add(20);
  myList.add(30);

  System.out.println("Elements in myList are");
  System.out.println(myList);
  
  System.out.println("Clearing myList");
  myList.clear();
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
 }
}

Output
Elements in myList are
[10, 20, 30]
Clearing myList
Elements in myList are
[]

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment