WorksheetsString Methods
Total questions: 10
Worksheet time: 30mins
Choose the line that assigns "love" to str2.
str2 = str.substring(2,6);
str2 = str.substring(2,5);
str2 = str.substring(2);
str2 = str.substring(4);
Choose the line that assigns "boba." to str2.
str2 = str.substring(7);
str2 = str.substring(7,11);
str2 = str.substring(8,12);
str2 = str.substring(8);
Choose the line that assigns "I" to str2.
str2 = str.substring(0,1);
str2 = str.substring(1,2);
str2 = str.substring(0);
str2 = str.substring(1);
What is the output from running this code block?
equals method
== operator
(Nothing)
equals method
== operator
What is the result of running this code block?
"." is printed.
An exception is thrown.
"America." is printed.
"a" is printed.
What is the result of running this code block?
"." is printed.
An exception is thrown.
"America." is printed.
"a" is printed.
What method-call below could be used to determine whether str contains the String "States"? Choose all that apply.
str.contains("States")
str.indexOf("States")
str.equals("States")
str.compareTo("States")
What line of code assigns the first position of the String "time!" to the variable index?
index = str.indexOf("time!");
index = str.indexOf(5);
index = str.contains("time!");
index = str.contains(5);
What could possibly be the output from running this code block?
-4
0
15
true
Which method calls could be reliably used to decide whether the two strings are equal?
str.compareTo(str2)
str.equals(str2)
str == str2
str.contains(str2)
