StringBuilder bd = new StringBuilder('[');
Iterator<String> iter = names.iterator();
while (iter.hasNext()) {
bd.append(iter.next());
if (iter.hasNext()) {
bd.append(", ");
}
}
bd.append(']');
return bd.toString();
I thought the output would come out looking something like [<some stuff, if any>]
, but it looks like <some stuff, if any>]
instead.
What is going on?
Change the char in the constructor args to a String.
StringBuilder bd = new StringBuilder("[");
Otherwise the char is being converted to an int to define initial capacity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With