Page 1 of 1

About Question Id com.enthuware.ets.scjp.v6.2.103 : API Contents

Posted: Tue May 03, 2011 4:02 pm
by cbs
Question 18:

Answer given does not match the ouput i get when i execute:


StringBuilder b1= new StringBuilder("snorkler");
StringBuilder b2= new StringBuilder("yoodler")
b1.append(b2.substring(2,5).toUpperCase());
b2.insert(3,b1.append("a"));
b1.replace(3,4,b2.substring(4)).append(b2.append(false));

Given Answer:

b1 b2
snorklerODL yoodler
snorklera yoosnorkleradler
snolerkleryoodlerfalse yoodlerfalse


My Output:
snorklerODL yoodler
snorklerODLa yoosnorklerODLadler
snonorklerODLadlerklerODLayoosnorklerODLadlerfalse yoosnorklerODLadlerfalse

Please let me know if i am correct.

Thanks

(Paul - Update the subject to include questionid)

Re: API Contents

Posted: Tue May 03, 2011 7:56 pm
by admin
Hello,
The given answer is correct. You need to execute the three statements independent of each other as the question suggests.

HTH,
Paul.

Re: About Question Id com.enthuware.ets.scjp.v6.2.103 : API Contents

Posted: Tue Jul 26, 2011 11:37 am
by Deepa
Paul,

I didn't understand the purpose of 4 in replace() of the following line
b1.replace(3,4,b2.substring(4)).append(b2.append(false));
replace method takes two arguments but here we have 3 args.... the output is fine if 4 is not there.... can u explain me?

Re: About Question Id com.enthuware.ets.scjp.v6.2.103 : API Contents

Posted: Tue Jul 26, 2011 1:20 pm
by admin
Replace method takes 3 (and not 2) arguments:
StringBuilder replace(int start, int end, String str)
Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start. (This sequence will be lengthened to accommodate the specified String if necessary.)
HTH,
Paul.

Re: About Question Id com.enthuware.ets.scjp.v6.2.103 : API Contents

Posted: Tue Jul 26, 2011 3:07 pm
by Guest
Thanks Paul!!
Do we have to study Java docs for all the string functions?

Re: About Question Id com.enthuware.ets.scjp.v6.2.103 : API Contents

Posted: Tue Jul 26, 2011 3:58 pm
by admin
Not all but if you just go through the ones that are included in the question of JQ+, you should be good.