Java Single LinkedList I am a CS student and I was wondering is this code looks clean. I tested it and it passed every tested but I think the delete(Node node) is a bit long, I did not find a way to reduce it 

Node class  

public class Node {
      private int data;
      private Node next;
      Node(int data){
        this.data = data;
      }

      public int getValue(){
        return this.data;
      }

      public void setNext(Node next){
        this.next = next;
      }

      public Node nextNode(){
        return this.next;
      }
    }


LinkedList class

public class LinkedList {
  Node head;
  Node tail;
  int size = 0;


  public void add(Node node){
    if(tail == null &amp;&amp; head == null){
      tail = node;
      head = node;

    } else{
      tail.setNext(node);
      tail = tail.nextNode();
    }
    size ++;
  }

  public int getSize(){
    return this.size;
  }
  public int getTail(){
    if(tail == null){
      return -1;
    } else {
      return tail.getValue();
    }
  }

  public void delete(Node node){
    if(isPresent(node)){
      if(size == 1){
        this.tail = null;
        this.head = null;
        size = 0;
      }
      else if(node == head){
        head = head.nextNode();
        size --;
      }

      else if(node == tail){
        Node iterator = head;
        while(iterator.nextNode().nextNode() != tail){
          iterator = iterator.nextNode();
        }
        tail = iterator.nextNode();
        iterator.nextNode().setNext(null);
        size --;
      }

      else{
        Node iterator = head;
        while(iterator.nextNode() != node){
          iterator = iterator.nextNode();
        }
        iterator.setNext(iterator.nextNode().nextNode());
        size --;
      }
    }
  }

  public int getHead(){
    if(head == null){
      return -1;
    } else {
      return head.getValue();
    }
  }


  public void printList(){
    Node iterator = head;

    while(iterator != null){
      System.out.println(iterator.getValue());
      iterator = iterator.nextNode();
    }
  }

  public boolean isPresent(Node node){
    if(head == null){
      return false;
    }

    else if(head.getValue() == node.getValue()){
      return true;
    }

    else {
      Node iterator = head;
      while(iterator != null){
        if(iterator.getValue() == node.getValue()){
          return true;
        }
        iterator = iterator.nextNode();
      }
      return false;
    }
  }
}
Indeed the cases for delete can be reduced.

  public void delete(Node node) {
    Node prior = null;
    Node current = head;
    while (current != node &amp;&amp; current != null) {
      prior = current;
      current = current.next;
    }
    if (current != null) {
      if (prior == null) {
        head = current.next;
      } else {
        prior.next = current.next;
      }
      --size;
      if (current == tail) {
        tail = prior;
      }
    }
  }


In general one would keep Node an internal non-public class, for instance one would not
like people to play with the next field. Hence I would propose:

  public void delete(int value) {
    Node prior = null;
    Node current = head;
    while (current != null &amp;&amp; current.value != value) {
      prior = current;
      current = current.next;
    }
    if (current != null) {
      if (prior == null) {
        head = current.next;
      } else {
        prior.next = current.next;
      }
      --size;
      if (current == tail) {
        tail = prior;
      }
    }
  }


For the rest:


A tab of 4 spaces is still my favorite, probably still mainstream.
iterator is an unlucky naming, as there exist an Iterator in java, with a collection method iterator(). I used current.


And (as goodie) what about System.out.println(list);:

@Override
public String toString() {
    StringBuilder sb = new StringBuilder("[");
    Node current = head;
    while (current != null) {
      if (sb.length() &gt;= 1) {
          sb.append(", ");
      }
      sb.append(current.value);
      current = current.next;
    }
    sb.append("]");
    return sb.toString();
}