import java.util.Vector; import java.util.Iterator; public class Example { public static void main(String[] args) { Vectorvector = new Vector (); vector.add("Apple"); vector.add("Banana"); vector.add("Cherry"); Iterator iterator = vector.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } } }
import java.util.Vector; import java.util.Iterator; public class Example { public static void main(String[] args) { VectorBoth examples are using the java.util package library.vector = new Vector (); vector.add("Apple"); vector.add("Banana"); vector.add("Cherry"); Iterator iterator = vector.iterator(); while (iterator.hasNext()) { String element = iterator.next(); if (element.equals("Banana")) { iterator.remove(); } } } }