This Java Example shows how to remove all the elements from the specified LinkedList object in java.
Remove All Elements of Java LinkedList Example
This Java Example shows how to remove all the elements from the specified LinkedList
object in java. To remove all of the elements from LinkedList object we
use void clear() method.
Example: RemoveAllElementsLinkedList.java
package devmanuals.com; import java.util.*; public class RemoveAllElementLinkedList { public static void main(String[] args) { LinkedList LKLST = new LinkedList(); LKLST.add("Gyan"); LKLST.add("Singh"); LKLST.add("Arunesh"); LKLST.add("Kumar"); System.out.println("The LinkedList Elements are : " + LKLST); LKLST.clear(); System.out.println("The LinkedList Elements after removal : " + LKLST); } }
Output:
The LinkedList Elements are : [Gyan, Singh, Arunesh, Kumar]
The LinkedList Elements after removal : [] |
[ 0 ] Comments