Challenge - 5 Problems
String Creation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
What is the output of this Java code?
Consider the following Java code snippet:
String s1 = "hello";
String s2 = new String("hello");
System.out.println(s1 == s2);What will be printed?
Java
String s1 = "hello"; String s2 = new String("hello"); System.out.println(s1 == s2);
Attempts:
2 left
💻 code output
intermediate2:00remaining
What is the output of this Java code using StringBuilder?
Look at this code:
StringBuilder sb = new StringBuilder("abc");
sb.append("def");
System.out.println(sb.toString());What will be printed?
Java
StringBuilder sb = new StringBuilder("abc"); sb.append("def"); System.out.println(sb.toString());
Attempts:
2 left
🔧 debug
advanced2:00remaining
What error does this code raise?
Examine this Java code snippet:
String s = null; int length = s.length(); System.out.println(length);
What error will this code cause when run?
Java
String s = null; int length = s.length(); System.out.println(length);
Attempts:
2 left
💻 code output
advanced2:00remaining
What is the output of this code using String intern()?
Consider this Java code:
String s1 = new String("test");
String s2 = s1.intern();
String s3 = "test";
System.out.println(s2 == s3);What will be printed?
Java
String s1 = new String("test"); String s2 = s1.intern(); String s3 = "test"; System.out.println(s2 == s3);
Attempts:
2 left
🧠 conceptual
expert2:00remaining
How many String objects are created here?
Analyze this Java code snippet:
String s = "a" + "b" + new String("c");How many distinct String objects are created at runtime?
Attempts:
2 left
