String Manipulation - AP Computer Science A
Card 1 of 30
What is the result of '"Hello".equalsIgnoreCase("hello");'?
What is the result of '"Hello".equalsIgnoreCase("hello");'?
Tap to reveal answer
true. Case-insensitive comparison returns true for same content.
true. Case-insensitive comparison returns true for same content.
← Didn't Know|Knew It →
What is the output of '"abcdef".substring(2);'?
What is the output of '"abcdef".substring(2);'?
Tap to reveal answer
"cdef". Substring from index 2 to end of string.
"cdef". Substring from index 2 to end of string.
← Didn't Know|Knew It →
Which method returns a string representation of an object?
Which method returns a string representation of an object?
Tap to reveal answer
toString(). Converts any object to its string representation.
toString(). Converts any object to its string representation.
← Didn't Know|Knew It →
Find and correct: 'String s = "Java"; s = s.toLowercase();'
Find and correct: 'String s = "Java"; s = s.toLowercase();'
Tap to reveal answer
Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.
Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.
← Didn't Know|Knew It →
What is the output of '"Hello World".indexOf("o");'?
What is the output of '"Hello World".indexOf("o");'?
Tap to reveal answer
- First 'o' appears at position 4 in 'Hello World'.
- First 'o' appears at position 4 in 'Hello World'.
← Didn't Know|Knew It →
What is the output of '"Java".charAt(0);'?
What is the output of '"Java".charAt(0);'?
Tap to reveal answer
'J'. Returns the character at index 0 (first position).
'J'. Returns the character at index 0 (first position).
← Didn't Know|Knew It →
What method returns the last index of a character in a string?
What method returns the last index of a character in a string?
Tap to reveal answer
lastIndexOf(). Returns position of final occurrence of specified character.
lastIndexOf(). Returns position of final occurrence of specified character.
← Didn't Know|Knew It →
Identify the method that returns the index of a character in a string.
Identify the method that returns the index of a character in a string.
Tap to reveal answer
indexOf(). Returns position of first occurrence of specified character.
indexOf(). Returns position of first occurrence of specified character.
← Didn't Know|Knew It →
Find and correct: 'String s = "abc"; s = s.concat('d');'
Find and correct: 'String s = "abc"; s = s.concat('d');'
Tap to reveal answer
Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.
Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.
← Didn't Know|Knew It →
Which method checks if a string ends with a specific suffix?
Which method checks if a string ends with a specific suffix?
Tap to reveal answer
endsWith(). Tests if the string concludes with specified text.
endsWith(). Tests if the string concludes with specified text.
← Didn't Know|Knew It →
What is the output of '"Hello".substring(1, 4);'?
What is the output of '"Hello".substring(1, 4);'?
Tap to reveal answer
"ell". Extracts characters from index 1 to 3 (exclusive).
"ell". Extracts characters from index 1 to 3 (exclusive).
← Didn't Know|Knew It →
Which method checks if a string starts with a specific prefix?
Which method checks if a string starts with a specific prefix?
Tap to reveal answer
startsWith(). Tests if the string begins with specified text.
startsWith(). Tests if the string begins with specified text.
← Didn't Know|Knew It →
What method checks if a string is empty in Java?
What method checks if a string is empty in Java?
Tap to reveal answer
isEmpty(). Returns true if string length is zero.
isEmpty(). Returns true if string length is zero.
← Didn't Know|Knew It →
Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'
Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'
Tap to reveal answer
Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.
Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.
← Didn't Know|Knew It →
What is the output of '" hello ".trim();'?
What is the output of '" hello ".trim();'?
Tap to reveal answer
"hello". Removes whitespace from both ends of string.
"hello". Removes whitespace from both ends of string.
← Didn't Know|Knew It →
Find and correct: 'String s = "Java"; s = s.toLowercase();'
Find and correct: 'String s = "Java"; s = s.toLowercase();'
Tap to reveal answer
Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.
Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.
← Didn't Know|Knew It →
What is the output of '"Hello".substring(1, 4);'?
What is the output of '"Hello".substring(1, 4);'?
Tap to reveal answer
"ell". Extracts characters from index 1 to 3 (exclusive).
"ell". Extracts characters from index 1 to 3 (exclusive).
← Didn't Know|Knew It →
Find and correct the error: 'String s = new String("hello").toLowerCase();'
Find and correct the error: 'String s = new String("hello").toLowerCase();'
Tap to reveal answer
Correct: 'String s = "hello".toLowerCase();'. String literals don't need 'new String()' constructor.
Correct: 'String s = "hello".toLowerCase();'. String literals don't need 'new String()' constructor.
← Didn't Know|Knew It →
Which method checks if a string ends with a specific suffix?
Which method checks if a string ends with a specific suffix?
Tap to reveal answer
endsWith(). Tests if the string concludes with specified text.
endsWith(). Tests if the string concludes with specified text.
← Didn't Know|Knew It →
What is the output of '"abcdef".lastIndexOf("e");'?
What is the output of '"abcdef".lastIndexOf("e");'?
Tap to reveal answer
- Last occurrence of 'e' is at index 4.
- Last occurrence of 'e' is at index 4.
← Didn't Know|Knew It →
Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'
Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'
Tap to reveal answer
Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.
Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.
← Didn't Know|Knew It →
Identify the method that returns the index of a character in a string.
Identify the method that returns the index of a character in a string.
Tap to reveal answer
indexOf(). Returns position of first occurrence of specified character.
indexOf(). Returns position of first occurrence of specified character.
← Didn't Know|Knew It →
What method returns a substring from a string in Java?
What method returns a substring from a string in Java?
Tap to reveal answer
substring(). Extracts a portion of the string by index range.
substring(). Extracts a portion of the string by index range.
← Didn't Know|Knew It →
Which method returns a character array representing the string?
Which method returns a character array representing the string?
Tap to reveal answer
toCharArray(). Converts string into array of individual characters.
toCharArray(). Converts string into array of individual characters.
← Didn't Know|Knew It →
What is the result of '"Hello".equalsIgnoreCase("hello");'?
What is the result of '"Hello".equalsIgnoreCase("hello");'?
Tap to reveal answer
true. Case-insensitive comparison returns true for same content.
true. Case-insensitive comparison returns true for same content.
← Didn't Know|Knew It →
What is the output of '"Hello World".indexOf("o");'?
What is the output of '"Hello World".indexOf("o");'?
Tap to reveal answer
- First 'o' appears at position 4 in 'Hello World'.
- First 'o' appears at position 4 in 'Hello World'.
← Didn't Know|Knew It →
Which method checks if a string starts with a specific prefix?
Which method checks if a string starts with a specific prefix?
Tap to reveal answer
startsWith(). Tests if the string begins with specified text.
startsWith(). Tests if the string begins with specified text.
← Didn't Know|Knew It →
Find and correct: 'String s = "abc"; s = s.concat('d');'
Find and correct: 'String s = "abc"; s = s.concat('d');'
Tap to reveal answer
Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.
Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.
← Didn't Know|Knew It →
What method returns the length of a string in Java?
What method returns the length of a string in Java?
Tap to reveal answer
length(). Returns the number of characters in the string.
length(). Returns the number of characters in the string.
← Didn't Know|Knew It →
Identify the method to convert a string to uppercase in Java.
Identify the method to convert a string to uppercase in Java.
Tap to reveal answer
toUpperCase(). Converts all characters to their uppercase equivalents.
toUpperCase(). Converts all characters to their uppercase equivalents.
← Didn't Know|Knew It →