ArrayList Vector

Definition

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.

Example

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

Language German

Java JSF XHTML WML JavaScript GlassFish MySQL NetBeans

Imprint

Visits
582379
Today
35