class MyList { private ListElement head, tail; //Forward declaration void add(Object value) { if (tail != null) { tail.next = new ListElement(value); tail = tail.next; } else { head = tail = new ListElement(value); } } Object remove() { assert head != null; // don't remove on empty list Object result = head.value; head = head.next; if (head == null) { //was that the last? tail = null; } return result; } //Nested class needed only in the implementation of MyList private class ListElement { ListElement(Object value) {this.value = value;} Object value; ListElement next; //defaults to null as desired } }