clear Method
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

List.clear Method

Visual Studio 2005

Removes all the elements from a List object.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public abstract void clear();

// list-clear.jsl
// List example

import java.util.*;

public class MyClass
{
    public static void main(String[] args)
    {
        // Create a linked list object:
        LinkedList lList =  new LinkedList();

        // Add some elements:
        lList.add("100");
        lList.add("200");
        lList.add("300");
        lList.add("400");

        // Get and display the elements:
        System.out.println("The elements of the list are:");
        for (int i=0; i<lList.size(); i++)
            System.out.println(lList.get(i));

        // Print the size:
        System.out.println("The size of the list is: " + lList.size());

        // Clear the list:
        lList.clear();
        System.out.print("The list has been cleared. ");

        // Print the new size:
        System.out.println("The size is now: " + lList.size());
    }
}

/*
Output:
The elements of the list are:
100
200
300
400
The size of the list is: 4
The list has been cleared. The size is now: 0
*/
Show:
© 2016 Microsoft