My own expandable list I wondered how an expandable list could be implemented. My first thought: You could create a class that has an array and you can create a new array each time the user wants to append an element and than you can copy the old array plus the new element into the new array. But this seems very inefficient to me. Then I read something about so called linked lists. The idea is very simple. Such a list has nodes. Nodes contain an object and another node. The nodes can be linked as required. I had my thoughts about that and I tried to write a class that follows this thought.

LinkedList.java

package linkedList;

public class LinkedList&lt;T&gt; {
    private Node&lt;T&gt; startNode;

    public LinkedList() {
        startNode = new Node&lt;T&gt;();
    }

    private Node&lt;T&gt; getEmptyNode() {
        Node&lt;T&gt; currentNode = this.startNode;
        while (currentNode.hasObject()) {
            currentNode = currentNode.getNextNode();
        }
        return currentNode;
    }

    public void insert(T object) {
        Node&lt;T&gt; emptyNode = getEmptyNode();
        emptyNode.setObject(object);
        emptyNode.setNextNode(new Node&lt;T&gt;());
    }

    public int getNumberOfElements() {
        Node&lt;T&gt; currentNode = startNode;
        int numberOfElements = 0;
        while (currentNode.hasObject()) {
            numberOfElements++;
            currentNode = currentNode.getNextNode();
        }
        return numberOfElements;
    }

    private Node&lt;T&gt; getNodeByIndex(int index) {
        Node&lt;T&gt; currentNode = startNode;
        for (int i = 0; i &lt; index; i++) {
            currentNode = currentNode.getNextNode();
        }
        return currentNode;
    }

    public T get(int index) {
        return getNodeByIndex(index).getObject();
    }

    public void delete(int index) {
        if (index == 0) {
            startNode = getNodeByIndex(1);
            return;
        }

        // if index equals last available index
        if (index == (getNumberOfElements() - 1)) {
            Node&lt;T&gt; nodeBefore = getNodeByIndex(index - 1);
            nodeBefore.setNextNode(null);
            return;
        }

        Node&lt;T&gt; nodeBefore = getNodeByIndex(index - 1);
        Node&lt;T&gt; nodeBehind = getNodeByIndex(index + 1);
        nodeBefore.setNextNode(nodeBehind);
    }
}


Node.java

package linkedList;

public class Node&lt;T&gt; {
    private T object;
    private Node&lt;T&gt; nextNode;

    public Node() {
        this.object = null;
        this.nextNode = null;
    }

    public boolean hasObject() {
        return object != null;
    }

    public boolean hasNextNode() {
        return nextNode != null;
    }

    public T getObject() {
        return object;
    }

    public Node&lt;T&gt; getNextNode() {
        return nextNode;
    }

    public void setNextNode(Node&lt;T&gt; nextNode) {
        this.nextNode = nextNode;
    }

    public void setObject(T object) {
        this.object = object;
    }
}


Main.java

package linkedList;

public class Main {
    public static void main(String[] args) {
        LinkedList&lt;String&gt; linkedList = new LinkedList&lt;&gt;();
        linkedList.insert("Hallo");
        linkedList.insert("Test");
        linkedList.insert("Wie gehts?");
        linkedList.insert("Freuen sie sich?");
        System.out.println("Anzahl der Elemente: " + linkedList.getNumberOfElements());
        System.out.println("Drittes Element: " + linkedList.get(2));
        System.out.println("Alle Elemente:");
        for (int i = 0; i &lt; linkedList.getNumberOfElements(); i++) {
            System.out.println(linkedList.get(i));
        }

        linkedList.delete(2);
        System.out.println("Alle Elemente:");
        for (int i = 0; i &lt; linkedList.getNumberOfElements(); i++) {
            System.out.println(linkedList.get(i));
        }
    }
}


Because this is my first attempt to do such stuff I am wondering what things can be improved. Is there a way to make this more efficient? Is the code clean and readable enough?
You are on the right track, and I think you would benefit by having your class implement the Java List&lt;T&gt; interface like so:

public class LinkedList&lt;T&gt; implements List&lt;T&gt; {


You would then have to change your methods so that their names and signatures conform to the interface. You can read about the details here for Java 7 or here for Java 8. If you do this then you could pass instances of your class into already implemented functions like Collections.sort.