ArrayList is a class, which contains duplicates values and it uses generics concept to store values in ArrayList.
import java.util.ArrayList;
public class arraylist {
public static void main(String args[])
{
ArrayList<Integer> al= new ArrayList<Integer>();
al.add(10);
al.add(10);
al.add(20);
//al.add(0, "nitu");
System.out.println(al);
}
}
Output:
Note: From the above output, you can see that 10 repeats two times. Now, if you remove generics then the ArrayList can contain different types of values in the list, as int and String type, or float.
import java.util.ArrayList;
public class arraylist {
public static void main(String args[])
{
ArrayList al= new ArrayList();
al.add(10);
al.add(10);
al.add(20);
al.add(0, "nitu");
System.out.println(al);
}