Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Hard
Question 12
Consider the code:
- public class Test
- {
- public static void main(String[] args)
- {
- StringBuilder sb = new StringBuilder();
- sb.append("durga");
- sb.deleteCharAt(0);
- sb.delete(1,3);
- System.out.println(sb);
- }
- }
What is the result ?
-
A
ur
-
B
ua
-
C
uga
-
D
ga
Reveal correct answer
Correct answer: B
Explanation
sb.deleteCharAt(0);===>it deletes 'd' and now content is "urga" sb.delete(1,3);===>delete characters from index 1 to 2. Hence "rg" will be deleted. Hence the output is: uaDiscussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
