WorksheetsJava String - Assessment
Total questions: 5
Worksheet time: 2mins
What does the length() method return for this string?
String str = "Hello World";
System.out.println(str.length());
10
11
12
13
Which method is used to join two strings efficiently?
str1 + str2
str1.concat(str2)
str1.join(str2)
str1.append(str2)
What is the result of the following code?
String s1 = "Java";
String s2 = "Programming";
String result = s1.concat(s2);
System.out.println(result);
Java Programming
JavaProgramming
Java + Programming
Compilation error
Why is using + in a loop inefficient for string concatenation?
It is faster.
It modifies the original string.
It creates a new string object every time.
It uses the string pool.
Why is the following code less efficient when using new String()?
String s1 = new String("Java");
String s2 = "Java";
System.out.println(s1 == s2);
Creates two string objects unnecessarily
== compares values, not references
equals() should be used for comparison
Causes a compilation error
