Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

The String Class

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.
What is a string in Java?
a)
A collection of booleans
b)
A collection of integers
c)
A collection of characters
d)
A collection of floats
2.
What does it mean for a string to be immutable?
a)
It can be updated once created
b)
It can't be deleted once created
c)
It can't be updated once created
d)
It can be deleted once created
3.
What does the charAt() method do?
a)
Returns the length of a string
b)
Compares two given strings
c)
Converts the string to lowercase letters
d)
Returns a character at a specified position
4.
What does the equals() method do?
a)
Converts the string to lowercase letters
b)
Returns a character at a specified position
c)
Returns the length of a string
d)
Compares two given strings
5.
What does the concat() method do?
a)
Returns the length of a string
b)
Appends one string to the end of another
c)
Returns a character at a specified position
d)
Converts the string to lowercase letters
6.
What does the length() method do?
a)
Converts the string to lowercase letters
b)
Returns the length of a string
c)
Returns a character at a specified position
d)
Compares two given strings
7.
What does the toLowerCase() method do?
a)
Returns the length of a string
b)
Converts the string to uppercase letters
c)
Returns a character at a specified position
d)
Converts the string to lowercase letters
8.
What does the toUpperCase() method do?
a)
Returns a character at a specified position
b)
Converts the string to uppercase letters
c)
Returns the length of a string
d)
Converts the string to lowercase letters
9.
What does the indexOf() method do?
a)
Returns the length of a string
b)
Converts the string to lowercase letters
c)
Returns the first found position of a character
d)
Returns a character at a specified position
10.
What does the substring() method do?
a)
Converts the string to lowercase letters
b)
Returns a character at a specified position
c)
Returns the length of a string
d)
Extracts the substring based on index values, passed as an argument
11.
What is the output of the following code: String str = "Hello World"; System.out.println(str.charAt(4));
a)
o
b)
e
c)
H
d)
l
12.
What is the output of the following code: String str1 = "Hello"; String str2 = "World"; System.out.println(str1.concat(str2));
a)
Hello World
b)
HWeolrllod
c)
HelloWorld
d)
WorldHello
13.
What is the output of the following code: String str = "Hello World"; System.out.println(str.length());
a)
10
b)
12
c)
13
d)
11
14.
What is the output of the following code: String str = "Hello World"; System.out.println(str.toLowerCase());
a)
Hello World
b)
hELLO wORLD
c)
hello world
d)
HELLO WORLD
15.
What is the output of the following code: String str = "Hello World"; System.out.println(str.toUpperCase());
a)
hELLO wORLD
b)
hello world
c)
Hello World
d)
HELLO WORLD
16.
What is the output of the following code: String str = "Hello World"; System.out.println(str.indexOf('o'));
a)
7
b)
9
c)
8
d)
4
17.
What is the output of the following code: String str = "Hello World"; System.out.println(str.substring(6));
a)
Worl
b)
Hello World
c)
Hello
d)
World
18.
What is the output of the following code: String str = "Hello World"; System.out.println(str.substring(0, 5));
a)
Hello
b)
H
c)
Hello World
d)
World
19.
What is the output of the following code: String str1 = "Hello"; String str2 = "hello"; System.out.println(str1.equals(str2));
a)
False
b)
Error
c)
True
d)
None of the above
20.
What is the output of the following code: String str1 = "Hello"; String str2 = "hello"; System.out.println(str1.equalsIgnoreCase(str2));
a)

False

b)

Error

c)

True

d)

None of the above