wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java String class methods

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Which method would you use to check if two Strings are exactly the same?

a)

equals()

b)

equalsIgnoreCase()

c)

toUpperCase()

d)

toLowerCase()

2.

Which method was used to convert this String: "IT learners are clever" to "IT LEARNERS ARE CLEVER" ?

a)

toUpperCase()

b)

toLowerCase()

c)

equalsIgnoreCase()

d)

compareTo()

3.

Which method was used to convert this String: "Life is TOO SHORT to be BORED" to: "life is too short to be bored" ?

a)

toLowerCase()

b)

toUpperCase()

c)

equals()

d)

equalsIgnoreCase()

4.

Is String a primitive data type?

a)

Yes

b)

No

c)

Both

5.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

6.

Which data type gets returned from length() method in String class?

a)

double

b)

String

c)

int

d)

number

7.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

8.

String txt = "Hello World";

System.out.println(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

9.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

10.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"