trim() and setLength(int) were the correct answers.
In the explaination of the answer it says the following:
public void setLength(int newLength)
Sets the length of this String buffer. This string buffer is altered to represent a new character sequence whose length is specified by the argument. For every nonnegative index k less than newLength, the character at index k in the new character sequence is the same as the character at index k in the old sequence if k is less than the length of the old character sequence; otherwise, it is the null character '' (\u0000). In other words, if the newLength argument is less than the current length of the string buffer, the string buffer is truncated to contain exactly the number of characters given by the newLength argument.
If the newLength argument is greater than or equal to the current length, sufficient null characters ('\u0000') are appended to the string buffer so that length becomes the newLength argument.
The newLength argument must be greater than or equal to 0.
newLength - the new length of the buffer.
IndexOutOfBoundsException - if the newLength argument is negative.
Is this an error or am I missing something about the answer?
- Site Admin
- Posts: 8959
- Joined: Fri Sep 10, 2010 9:26 pm
Users browsing this forum: Bing [Bot] and 2 guests