Well, by default, every class in java gets the toString method from the Object class. The toString method of the Object class will print the class name , followed by @ and hash code .
You can override the toString method for LinkedList . For instance:
class MyLinkedList extends LinkedList { @Override public String toString() { return "MyLinkedList [size=" + size + ", first=" + first + ", last=" + last + ", modCount=" + modCount + "]"; } }
Then you can print it:
MyLinkedList list = new MyLinkedList (); System.out.println(list);
source share