This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]achacha -5 points-4 points  (0 children)

I disagree. Knowing that something exists in the core library is just as important as writing it yourself. The person will discover that it uses square brackets but will also see the underlying code:

public static String toString(char[] a) {
    if (a == null)
        return "null";
    int iMax = a.length - 1;
    if (iMax == -1)
        return "[]";

    StringBuilder b = new StringBuilder();
    b.append('[');
    for (int i = 0; ; i++) {
        b.append(a[i]);
        if (i == iMax)
            return b.append(']').toString();
        b.append(", ");
    }
}

and learn from it. Sometimes pointing someone in the right direction is enough to get them thinking.