It describes how to use the ArrayList collection in Java Program
It describes how to use the ArrayList collection in Java Program
Example of Java Arraylist Declaration
import java.util.ArrayList;
import java.util.List;
public class List1 {
public static void main(String[] args) {
List list=new ArrayList();
String names[]={"mac","john","alexender","rock","alex"};
for (int i = 0; i < names.length; i++) {
list.add(names[i]);
}
for (int i = 0; i < names.length; i++) {
System.out.println((i+1)+" : "+list.get(i));
}
}
}
Output
1 : mac
2 : john
3 : alexender
4 : rock
5 : alex