This Java Tutorial section demonstrates the use of the generic ArrayList in Java Program.
This Java Tutorial section demonstrates the use of the generic ArrayList in Java Program.
import java.util.ArrayList; import java.util.List; public class GenericList1 { public static void main(String[] args) { Listlist=new ArrayList (); list.add("aaa"); list.add("bbb"); list.add(1000); list.add("ccc"); list.add("ddd"); System.out.println(list); } } It gives compilation error GenericList1.java:9: cannot find symbol symbol : method add(int) location: interface java.util.List list.add(1000); ^ 1 error Example-2 import java.util.ArrayList; import java.util.List; public class GenericList2 { public static void main(String[] args) { List list=new ArrayList (); list.add("aaa"); list.add("bbb"); list.add("fff"); list.add("ccc"); list.add("ddd"); System.out.println(list); } } Output [aaa, bbb, fff, ccc, ddd]