package list;

public class List<T> {
    T value = null;
    List<T> next =  null;
    
    /** Constructor */
    List(T value, List<T> next) {
        this.value = value;
        this.next = next;
    }
    
    List<T> add(T value) {
        return new List<T>(value, this);
    }
    
    @Override
    public String toString() {
        List<T> here = this;
        String result = "";
        do {
            result += here.value + "  ";
            here = here.next;
        } while (here != null);
        return result;
    }
    
    public static void main(String[] args) {
        List<String> myList = new List<String>("One", null);
        myList = myList.add("Two");
        myList = myList.add("Three");
        System.out.println(myList);
    }
}
