Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 4

Given:

What is the result?

    Correct Answer: B

Discussion
qulytOption: B

HOWDY <-- sb.append("HOWDY"); *HOWDY <-- sb.insert(0, "*"); *HOLLY <-- sb.replace(3, 5, "LL"); *HOLLYCOW <-- sb.insert(6, "COW"); *HOW <-- sb.delete(2, 7); 4 <-- sb.length();

bharathdave

'-' indicates blank space HOWDY _HOWDY _HOLLY _HOLLYCOW _HOW

bharathdave

4 is the length.

Ankit1010Option: B

B - Correct Answer

UcefSoftOption: B

B is correct

d7bb0b2Option: A

why 4 ? if final string is _HCOW and has 5 elements

d7bb0b2

anwers: delete(2,7) delete 5 elements 2,3,4,5,6 => so 9 - 5 = 4 lol!

james2033Option: B

public class Tester { public static void main(String[] args) { StringBuilder sb = new StringBuilder(5); sb.append("HOWDY"); sb.insert(0, ' '); sb.replace(3, 5, "LL"); sb.insert(6, "COW"); sb.delete(2, 7); System.out.println(sb.length()); } } Result: 4. --> Choose B.

StavokOption: B

B IS CORRECT

aruni_mishraOption: B

B- Correct, see below with capacity also. HOWDY :: sb.length():5, sb.capacity(): 5 _HOWDY :: sb.length():6, sb.capacity(): 12 _HOLLY :: sb.length():6, sb.capacity(): 12 _HOLLYcow :: sb.length():9, sb.capacity(): 12 _How :: sb.length():4, sb.capacity(): 12

Mukes877Option: A

5 is correct answer because HOWDY _HOWDY _HOLLDY _HOLLDcowY _HowY 5

AlanRM

used : sb.insert(0,' '); exit console: HOWDY HOWDY HOLLY HOLLYCOW HOLLYOW 8

JGR_77Option: D

D is correct: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: offset 6, length 5 at java.base/java.lang.String.checkOffset(String.java:4572) at java.base/java.lang.AbstractStringBuilder.insert(AbstractStringBuilder.java:1170) at java.base/java.lang.StringBuilder.insert(StringBuilder.java:336) at com.jgr.temporal.main.Principal.main(Principal.java:16)

pikosssOption: B

B is correct: the capacity will be automatically extended