"ADTList@(followed by some jibberish)" is created by the default toString()
method. Override this to print something useful. This may require overriding in both the list implementation and the elements.
Assuming that ADTList
is your own implementation of a linked list, it's toString
method could look something like this:
@Override
public String toString() {
Iterator<Object> i = iterator();
if (! i.hasNext()) {
return "[]";
}
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
Object element = i.next();
sb.append(e == this ? "(this Collection)" : element);
if (! i.hasNext()) {
return sb.append(']').toString();
}
sb.append(", ");
}
}
This has been copied from the JDK's AbstractCollection
class, as Christoffer Hammarström mentioned in his comment. It adds characters to make it list-like, e.g. "[x,y,z]" and also handles the list containing itself.
It might also be worth mentioning that the 'gibberish' in the default toString
does actually have meaning. It is the name of the class the object is an instance of, and the hexadecimal value of object's hashCode
- where the default hashCode()
, will represent a memory location.