3:59 pm - Saturday February 25, 2017

Clear elements from LinkedList using void clear()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This tutorial explains how  to Clear elements from LinkedList using void clear() method

Removes all of the elements from this collection. The collection will  be empty after this

    method returns.

 We can remove the specific elements use with remove function .

 But clear method to empty the list.

Example

import java.util.ArrayList;

public class ArrayClear

{

   public static void main(String a[])

  {       

       ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

       arrlist.add(20);

       arrlist.add(30);

       arrlist.add(10);

       arrlist.add(50);

       for (Integer number : arrlist) {

         System.out.println("Number = " + number);

       }          

       System.out.println(""+arrlist);

       arrlist.clear();

       System.out.println(""+arrlist);

   }
}

Output

        Number = 20

       Number = 30

       Number = 10

       Number = 50

       [20, 30, 10, 50]

            []

BACK

Filed in: Java Examples

Comments are closed.