I keep on copy-pasting the following in my programs. I'm wondering if anyone of you uses similar code, perhaps in a library to achieve the same.
@Override
public String toString() {
String ret = prefix;
boolean first = true;
for (Component child : children) {
if (!first) {
ret += " " + separator + " ";
} else {
first = false;
}
ret += child.getName();
}
return ret + postfix;
}
PS: One could use StringBuilder instead of String. Got that.