public
synchronized boolean removeAll(Collection<?> c)
Removes
from this Vector all of its elements that are contained in the
specified Collection. Return true if this Vector changed as a result
of the call.
import java.util.*; class VectorRemoveAll{ public static void main(String args[]){ Vector<Integer> myVector; Collection<Integer> myColl; ListIterator<Integer> myIter; myVector = new Vector<> (); myColl = new ArrayList<> (); /*Add Elements to myVector*/ myVector.add(10); myVector.add(11); myVector.add(12); myVector.add(13); myVector.add(14); /* Add Elements to myColl */ myColl.add(10); myColl.add(12); myColl.add(20); System.out.println("Elements in myVector are "); System.out.println(myVector); System.out.println("Elements in myColl are "); System.out.println(myColl); System.out.println("\nRemoving myColl from myVector"); myVector.removeAll(myColl); System.out.println("\nElements in myVector are "); System.out.println(myVector); } }
Output
Elements in myVector are [10, 11, 12, 13, 14] Elements in myColl are [10, 12, 20] Removing myColl from myVector Elements in myVector are [11, 13, 14]
No comments:
Post a Comment