Java LinkedList clear Example
LinkedList class clear method example. This example shows you how to use clear method.
LinkedList class clear method example.public void clear() Removes all of the elements from this list.
Here is the code
/**
* @ # Clear.java
* A class repersenting use to clear method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Clear {
public static void main(String args[]) {
List list = new LinkedList();
int i = 0;
String str = "Rose India";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
System.out.println("list = " + list);
//Removes all of the elements from this list.
list.clear();
System.out.println("list = " + list);
}
} |
Output
list = [0, Rose India]
list = [] |
|