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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
cbs

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

Post 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)

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: API Contents

Post 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.
If you like our products and services, please help us by posting your review here.

Deepa

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

Post 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?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Guest

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

Post by Guest »

Thanks Paul!!
Do we have to study Java docs for all the string functions?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Not all but if you just go through the ones that are included in the question of JQ+, you should be good.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests