Java Strings
What is the output of the following statement: String myWords = "Paul Gary Tom"; myWords.indexOf('s')
-1
What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon." loc = str.indexOf("ov");
15
A string s has 85 characters. The last char is at position _____
84
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.
True
immutable
Unable to be changed or altered
Assuming that str is declared as follows, String str = "RSTUVWXYZ"; what value will be returned from str.charAt(5)?
W
What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);
diddl
If str is declared as String str = "ABCDEFGHI"; what will be returned from Character.toLowerCase(str.charAt(5))?
f
In Java, when a String is stored in memory, it is actually as a(n) ________.
list of characters
charAt(int i)
returns the character at index i
Str1 and str2 are both Strings, what method call would you use to see if they are the same?
str1.equals(str2) OR str2.equals(str1)
String objects are immutable
true
What is s after the following code segment is run? String s = "MN"; s.concat("Zoo")
MNZoo
length()
Returns the number of characters in a string
What will be printed after the following code is executed? String str = "abc456"; int i = 0; while ( i < 6 ) { if (Character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i++;
ABC