To create a list as arraylist as generic type, create object as below:
or, we can write as below:
ArrayList<String> ll = new ArrayList<String>();
ArrayList<Integer> ll = new ArrayList<Integer>();
Program:
import java.util.ArrayList;
public class Gcoll
{
public static void main(String args[])
{
ArrayList<String> ll = new ArrayList<String>();
ll.add("Heeera");
ll.add("Navneet");
ll.add("Babu");
ll.add("kaur");
//generic type of list is String
//ll.add(10);
System.out.println(ll);
ll.remove(3);
System.out.println(ll);
}
}
sample output:
[Heeera, Navneet, Babu, kaur]
[Heeera, Navneet, Babu]