The String Class Flashcards

1
Q

What is the correct way to compare strings for equality?

A

equals()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the value of x, given the following code?

String letters = “abcdefgh”;
char x = letters.charAt(3);

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the correct way to call a method that takes two parameters?

A

processData(3,6);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What, if anything, is the value of x given the following code?

String word = "Programming";
var x = word.indexOf('u');
A

-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The primitive data type ‘int’ has a corresponding class. How is this class named?

A

Integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What method would you typically use to locate the position of the final ‘ri’ in ‘piri-piri’?

A

lastIndexOf()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the effect of String’s trim() method?

A

Removes all spaces from the start and end of the String.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which is the correct method name for one which returns the number of characters in the string?

A

length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The primitive type char has a corresponding Class. What is it called?

A

Character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly