Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of String concatenation in loop
What is the output of the following Java code?
Java
public class Test { public static void main(String[] args) { String s = ""; for (int i = 0; i < 3; i++) { s += i; } System.out.println(s); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output of StringBuilder append in loop
What is the output of this Java code using StringBuilder?
Java
public class Test { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 3; i++) { sb.append(i); } System.out.println(sb.toString()); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Performance difference in string concatenation
Consider these two code snippets. Which one is faster for large loops and why?
1) Using String with += in a loop
2) Using StringBuilder with append in a loop
Attempts:
2 left
💻 code output
advanced2:00remaining
Output of StringBuilder reverse method
What is the output of this Java code?
Java
public class Test { public static void main(String[] args) { StringBuilder sb = new StringBuilder("hello"); sb.reverse(); System.out.println(sb.toString()); } }
Attempts:
2 left
🧠 conceptual
expert2:00remaining
Immutability and thread safety of String vs StringBuilder
Which statement correctly describes the difference between String and StringBuilder in Java regarding immutability and thread safety?
Attempts:
2 left
