Extensible list which can collect any objects. The difference between ArrayList and Vector is, that a ArrayList is not synchronized, but therefore faster. In most cases a ArrayList will be used.
Since Java 5 you can and should define the type of object the list contains. The advantages are, that you do not need to cast when retrieving an object and the compiler can early show errors.
List<User> list = new ArrayList<User>();
list.add(new User());
list.add(new User());
for (User user : list)
System.out.println(user.toString());
for (int i = 0; i < list.size(); i++)
System.out.println(list.get(i).toString());
Author: Johannes HammoudComments Date: 06.02.2006