Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.438 :

Posted: Sun Jan 02, 2011 11:30 pm
by ETS User
Which of these are not part of the StringBuffer class?
choose 2
trim( )
ensureCapacity(int )
append(boolean )
reverse( )
setLength(int)

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.
Parameters:
newLength - the new length of the buffer.
Throws:
IndexOutOfBoundsException - if the newLength argument is negative.

Is this an error or am I missing something about the answer?

Re: About Question com.enthuware.ets.scjp.v6.2.438 :

Posted: Mon Jan 03, 2011 1:46 pm
by admin
You are right. setLength() should not be a correct answer. Should be fixed asap.

thank you!