OO Programming with Java


Templates

  1. Arrays are indexed collections than have the advantage to get/set quickly the value of a element. Their disadvantage is their fixed size that has to be known in advance.
    Another possibility is to use linked lists that are illustrated by the code below:
public class Order {
  private String value;
  private Order  next;
  
  public Order(String value,Order next) {
    this.value = value; this.next  = next; }
  public Order() { this(null,null); }

  public void add(String value) {
    if (this.value == null) {
      this.value = value; return; }
    if (this.next == null) {
      this.next = new Order(value,null); return; }
    this.next.add(value);
  }
}

source


1 - 13