Is there any way to abbreviate the print()
and toString()
into one function in a Java linked list function or is there any explanation as to why someone would format this way?
public void print() {
System.out.println(this.toString());
}
@Override
public String toString() {
String display = "";
LinkedList current = this;
while (current != null) {
display += new Integer(current.head).toString() + ",";
current = current.tail;
}
display = display.substring(0, display.length()-1);
return display;
}