Skip to main content
updated
Source Link
josefx
  • 15.7k
  • 6
  • 42
  • 63

Your Node class does not override the toString() method and falls back to use the Object.toString() method instead.
Also I think it is a bit confusing that you add a value but return a Node instead of a value with get().

Update: to print the value of your Node add the following code to your Node class.

@Override public String toString(){return ""+ value;} 

Or you can change the get method in DoublyLinkedList to

public int get(int index) throws IndexOutOfBoundsException { if (index < 0 || index > length) { throw new IndexOutOfBoundsException(); } else { Node cursor = head; for (int i = 0; i < index; i++) { cursor = cursor.getNext(); } return cursor.getValue(); } } 

Your Node class does not override the toString() method and falls back to use the Object.toString() method instead.
Also I think it is a bit confusing that you add a value but return a Node instead of a value with get().

Your Node class does not override the toString() method and falls back to use the Object.toString() method instead.
Also I think it is a bit confusing that you add a value but return a Node instead of a value with get().

Update: to print the value of your Node add the following code to your Node class.

@Override public String toString(){return ""+ value;} 

Or you can change the get method in DoublyLinkedList to

public int get(int index) throws IndexOutOfBoundsException { if (index < 0 || index > length) { throw new IndexOutOfBoundsException(); } else { Node cursor = head; for (int i = 0; i < index; i++) { cursor = cursor.getNext(); } return cursor.getValue(); } } 
Source Link
josefx
  • 15.7k
  • 6
  • 42
  • 63

Your Node class does not override the toString() method and falls back to use the Object.toString() method instead.
Also I think it is a bit confusing that you add a value but return a Node instead of a value with get().