I got a StringIndexOutOfBoundsException
for setCharAt(int index, char ch)
:
StringBuilder word = new StringBuilder(4);
for(int i = 0; i < 4; i++)
word.setCharAt(i,'-');
StringBuilder(int capacity)
: Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
setCharAt(int index, char ch)
: The character at the specified index is set to ch.
The only thing I can think of is that no memory was allocated, but then what's the point of StringBuilder(int capacity)
?