Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java String - Assessment

Total questions: 5

Worksheet time: 2mins

Name
Class
Date
1.

What does the length() method return for this string?

String str = "Hello World";

System.out.println(str.length());

a)

10

b)

11

c)

12

d)

13

2.

Which method is used to join two strings efficiently?

a)

str1 + str2

b)

str1.concat(str2)

c)

str1.join(str2)

d)

str1.append(str2)

3.

What is the result of the following code?

String s1 = "Java";

String s2 = "Programming";

String result = s1.concat(s2);

System.out.println(result);

a)

Java Programming

b)

JavaProgramming

c)

Java + Programming

d)

Compilation error

4.

Why is using + in a loop inefficient for string concatenation?

a)

It is faster.

b)

It modifies the original string.

c)

It creates a new string object every time.

d)

It uses the string pool.

5.

Why is the following code less efficient when using new String()?

String s1 = new String("Java");

String s2 = "Java";

System.out.println(s1 == s2);

a)

Creates two string objects unnecessarily

b)

== compares values, not references

c)

equals() should be used for comparison

d)

Causes a compilation error