I'd like to improve this code.DoublyLinkList.javapublic class DoublyLinkList<T> {    private static class Node<T> {        private T data;        private Node next;        private Node prev;        public Node(T data) {            this.data = data;        }        public void displayNode() {            System.out.print(data +  );        }        @Override        public String toString() {            return data.toString();        }    }    public Node first = null;    public Node last = null;    public void addFirst(T data) {        Node newNode = new Node(data);        if (isEmpty()) {            newNode.next = null;            newNode.prev = null;            first = newNode;            last = newNode;        } else {            first.prev = newNode;            newNode.next = first;            newNode.prev = null;            first = newNode;        }    }    public boolean isEmpty() {        return (first == null);    }    public void displayList() {        Node current = first;        while (current != null) {            current.displayNode();            current = current.next;        }        System.out.println();    }    public void removeFirst() {        if (!isEmpty()) {            Node temp = first;            if (first.next == null) {                first = null;                last = null;            } else {                first = first.next;                first.prev = null;            }            System.out.println(temp.toString() +  is popped from the list);        }    }    public void removeLast() {        Node temp = last;        if (!isEmpty()) {            if (first.next == null) {                first = null;                last = null;            } else {                last = last.prev;                last.next = null;            }        }        System.out.println(temp.toString() +  is popped from the list);    }}DoublyLinkListDemo.javapublic class DoublyLinkListDemo {    public static void main(String[] args) {        DoublyLinkList newList = new DoublyLinkList();        newList.addFirst(arun);        newList.addFirst(prakash);        newList.addFirst(70);        newList.addFirst(80);        newList.addFirst(30);        newList.displayList();        newList.removeFirst();        newList.removeFirst();        newList.removeFirst();        newList.removeLast();        newList.displayList();    }}
Implementation of a doubly linked list in Java
java;beginner;linked list
I think your code looks good, I just have a couple of thoughts:Implementing InterfacesAs you are creating a list, it would make sense to implement the Java List interface. It would mean implementing more methods than you have right now, but you can always throw an UnsupportedOperationException if you don't need a specific method (although some more methods wouldn't hurt, like add(int i), etc).If you don't want to do that, I would at least implement Iterable, that way you could simplify your displayList method, and it would generally be easier to work with your list.Displaying CodeI wouldn't add methods to the list that outputs the list directly. Overriding toString is good, but printing shouldn't be the job of a list. So instead of having displayList, I would override toString in the list as well, and then just change newList.displayList(); to System.out.println(list.toString()), and remove all display methods.Reporting that an element is removed also shouldn't happen in the list. ExceptionsRight now, if a node is removed that doesn't exist, nothing happens. You might want to throw an IndexOutOfBoundsException or similar.Stylesimple return statements don't need parentheses (return (first == null); -> return first == null;)for naming, see @carls comment (although I wouldn't use pop (or push), because it implies that an element is returned, which it isn't).