OO Programming with Java


Lists & Iterators

  1. The preceding structure is simply a LinkedList that is already defined in Java in the java.util package. This class implements the List interface that has other possible implementations:

So, an application can simply use any list, in design phase, then choose the implementation adapted to the target platform:

public static void main(String[] args) {
  List<String> orders = new LinkedList<String>();  // memory optimization
  // orders = new ArrayList<String>();             // computations optimization
  orders.add("Chicken"); orders.add("French Fries"); orders.add("Salad");
  System.out.println(orders);
}

As a remark, the "orders" type can be explicitly defined by:

public class TOrder extends ArrayList<Item> { ... }

5 - 13