In this section of tutorial we will learn how to use the Generics with the Iterator interface. We will create an example using Generics in Iterator and ArrayList
In this section of tutorial we will learn how to use the Generics with the Iterator interface. We will create an example using Generics in Iterator and ArrayList
import java.util.ArrayList; import java.util.Iterator; public class generic { public static void main(String[] args) { ArrayListlist = new ArrayList (); list.add("india"); list.add("china"); // list.add(2000);//gives error Iterator it = list.iterator(); while (it.hasNext()) System.out.println(it.next()); } }
Output
india china