By candid | Posted :
Jun 24, 2015
| Updated :
Jun 24, 2015
Removes all of the elements from this list. The list will be empty after this call returns.
Program
package com.candidjava;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.clear() method removes all of the
* elements from this list.
*/
public class LinkedListClear {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("kamal");
System.out.println("LinkedList:" + list);
list.clear();
System.out.println("LinkedList:" + list);
}
}
Output
LinkedList:[anandh, hari, vinoth, kamal]
LinkedList:[]
Explanation
public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.