Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why is this not an infinite loop?

843789Apr 15 2010 — edited Apr 15 2010
The following method is taken from an implementation of LinkedList. It is not an infinite looping recursion, even though the method seems to invoke itself.
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("[");
        Node<E> current = head;
        for (int i = 0; i < size; i++) {
            result.append(current.element);
            current = current.next;
            if (current != null) {
                result.append(", ");
            } else {
                result.append("]");
            }
        }
        return result.toString();
    }
I presume that the penultimate line invokes a super.toString() method. But I feel insecure with this presumption. A confirmation or an alternative explanation would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 13 2010
Added on Apr 15 2010
4 comments
138 views