public
void clear()
Removes
all of the elements from this list.
import java.util.*; class LinkedListClear{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<Integer> (); myList.add(10); myList.add(20); myList.add(30); System.out.println("Elements in myList are"); System.out.println(myList); System.out.println("Clearing myList"); myList.clear(); System.out.println("Elements in myList are"); System.out.println(myList); } }
Output
Elements in myList are [10, 20, 30] Clearing myList Elements in myList are []
No comments:
Post a Comment