Top Posters
Since Sunday
10
p
4
h
4
c
4
d
3
3
c
3
t
3
u
3
A
3
B
3
j
3
New Topic  
rizumidancer rizumidancer
wrote...
Posts: 507
Rep: 6 0
4 years ago
Analyze the following code.

class Test {
public static void main(String[] args) {
StringBuilder strBuf = new StringBuilder(4);
strBuf.append("ABCDE");
System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(5));
}
}


▸ The program has a compilation error because you cannot specify initial capacity in the StringBuilder constructor.

▸ The program has a runtime error because because the buffer's capacity is 4, but five characters "ABCDE" are appended into the buffer.

▸ The program compiles and runs fine.

▸ The program has a runtime error because the length of the string in the buffer is 5 after "ABCDE" is appended into the buffer. Therefore, strBuf.charAt(5) is out of range.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 57 times
1 Reply
Replies
Answer verified by a subject expert
jenniferagrethejenniferagrethe
wrote...
Posts: 369
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here

Related Topics

rizumidancer Author
wrote...

4 years ago
Thanks for your help!!
wrote...

Yesterday
Correct Slight Smile TY
wrote...

2 hours ago
Thanks
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1059 People Browsing
Related Images
  
 339
  
 292
  
 695
Your Opinion
Do you believe in global warming?
Votes: 423