AP Computer Science a Flashcards: String Manipulation

Study String Manipulation in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

String Manipulation

0 mastered0 still learning

0% Complete

QUESTION
1/ 62

Which method checks if a string ends with a specific suffix?

Tap card or press Space to flip

ANSWER

endsWith(). Tests if the string concludes with specified text.

How well did you know it?

Card 1 / 62

What this deck covers

This deck focuses on String Manipulation, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Which method checks if a string ends with a specific suffix?

Answer: endsWith(). Tests if the string concludes with specified text.

Flashcard 2: What method compares two strings lexicographically in Java?

Answer: compareTo(). Returns negative, zero, or positive for alphabetical ordering.

Flashcard 3: What method checks if a string contains a specified sequence of char values?

Answer: contains(). Tests if string includes specified character sequence.

Flashcard 4: Which method checks if a string ends with a specific suffix?

Answer: endsWith(). Tests if the string concludes with specified text.

Flashcard 5: What is the output of '"Hello World".indexOf("o");'?

Answer:

  1. First 'o' appears at position 4 in 'Hello World'.

Flashcard 6: Find and correct: 'String s = "Java"; s = s.toLowercase();'

Answer: Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.

Flashcard 7: Which method returns a string representation of an object?

Answer: toString(). Converts any object to its string representation.

Flashcard 8: What is the output of '" hello ".trim();'?

Answer: "hello". Removes whitespace from both ends of string.

Flashcard 9: What is the output of '"Hello World".indexOf("o");'?

Answer:

  1. First 'o' appears at position 4 in 'Hello World'.

Flashcard 10: What method converts a string to lowercase in Java?

Answer: toLowerCase(). Converts all characters to their lowercase equivalents.

Flashcard 11: What is the output of '"abcdef".lastIndexOf("e");'?

Answer:

  1. Last occurrence of 'e' is at index 4.

Flashcard 12: What is the output of '"Hello".substring(1, 4);'?

Answer: "ell". Extracts characters from index 1 to 3 (exclusive).

Flashcard 13: What is the output of '"Hello".substring(1, 4);'?

Answer: "ell". Extracts characters from index 1 to 3 (exclusive).

Flashcard 14: What method checks if a string contains a specified sequence of char values?

Answer: contains(). Tests if string includes specified character sequence.

Flashcard 15: Which method checks if a string starts with a specific prefix?

Answer: startsWith(). Tests if the string begins with specified text.

Flashcard 16: Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'

Answer: Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.

Flashcard 17: What method returns a new string resulting from replacing all occurrences of oldChar?

Answer: replace(). Replaces characters without regex pattern matching.

Flashcard 18: What method returns a new string resulting from replacing all occurrences of oldChar?

Answer: replace(). Replaces characters without regex pattern matching.

Flashcard 19: What is the output of '"Java".charAt(0);'?

Answer: 'J'. Returns the character at index 0 (first position).

Flashcard 20: What method returns the length of a string in Java?

Answer: length(). Returns the number of characters in the string.

Flashcard 21: What method returns the last index of a character in a string?

Answer: lastIndexOf(). Returns position of final occurrence of specified character.

Flashcard 22: Identify the method to trim whitespace from both ends of a string.

Answer: trim(). Removes leading and trailing whitespace characters.

Flashcard 23: What is the output of '"abcdef".substring(2);'?

Answer: "cdef". Substring from index 2 to end of string.

Flashcard 24: What is the output of '" hello ".trim();'?

Answer: "hello". Removes whitespace from both ends of string.

Flashcard 25: Which method concatenates two strings in Java?

Answer: concat(). Appends one string to the end of another.

Flashcard 26: Which method checks if two strings are equal in Java?

Answer: equals(). Compares string content for exact equality.

Flashcard 27: What method returns the length of a string in Java?

Answer: length(). Returns the number of characters in the string.

Flashcard 28: What is the result of '"Hello".equalsIgnoreCase("hello");'?

Answer: true. Case-insensitive comparison returns true for same content.

Flashcard 29: Identify the method to convert a string to uppercase in Java.

Answer: toUpperCase(). Converts all characters to their uppercase equivalents.

Flashcard 30: Which method checks if two strings are equal in Java?

Answer: equals(). Compares string content for exact equality.

Flashcard 31: What method converts a string to lowercase in Java?

Answer: toLowerCase(). Converts all characters to their lowercase equivalents.

Flashcard 32: Find and correct: 'String s = "abc"; s = s.concat('d');'

Answer: Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.

Flashcard 33: Identify the method that returns the index of a character in a string.

Answer: indexOf(). Returns position of first occurrence of specified character.

Flashcard 34: Find and correct: 'String s = "abc"; s = s.concat('d');'

Answer: Correct: 's = s.concat("d");'. Character literals use single quotes, not double quotes.

Flashcard 35: Which method returns a character array representing the string?

Answer: toCharArray(). Converts string into array of individual characters.

Flashcard 36: Which method concatenates two strings in Java?

Answer: concat(). Appends one string to the end of another.

Flashcard 37: Identify the method to replace characters in a string.

Answer: replace(). Substitutes all occurrences of a character or substring.

Flashcard 38: Identify the method to convert a string to uppercase in Java.

Answer: toUpperCase(). Converts all characters to their uppercase equivalents.

Flashcard 39: Find and correct the error: 'System.out.println(s.charAt(5));' for 'String s = "Java";'

Answer: Correct: 'System.out.println(s.charAt(3));'. String 'Java' has length 4, so valid indices are 0-3.

Flashcard 40: Find and correct the error: 'String s = new String("hello").toLowerCase();'

Answer: Correct: 'String s = "hello".toLowerCase();'. String literals don't need 'new String()' constructor.

Flashcard 41: What method compares two strings lexicographically in Java?

Answer: compareTo(). Returns negative, zero, or positive for alphabetical ordering.

Flashcard 42: What is the output of '"Java".substring(1, 2);'?

Answer: "a". Extracts single character from index 1 to 2 (exclusive).

Flashcard 43: What is the output of '"abcdef".substring(2);'?

Answer: "cdef". Substring from index 2 to end of string.

Flashcard 44: What is the output of '"abcdef".lastIndexOf("e");'?

Answer:

  1. Last occurrence of 'e' is at index 4.

Flashcard 45: Identify the method that returns the index of a character in a string.

Answer: indexOf(). Returns position of first occurrence of specified character.

Flashcard 46: Find and correct: 'String s = "Java"; s = s.toLowercase();'

Answer: Correct: 's = s.toLowerCase();'. Method name is 'toLowerCase', not 'toLowercase'.

Flashcard 47: Identify the method to replace characters in a string.

Answer: replace(). Substitutes all occurrences of a character or substring.

Flashcard 48: What is the output of '"Java".charAt(0);'?

Answer: 'J'. Returns the character at index 0 (first position).

Flashcard 49: What is the result of '"abc".concat("xyz");'?

Answer: "abcxyz". Concatenation combines strings into single result.

Flashcard 50: What method returns a substring from a string in Java?

Answer: substring(). Extracts a portion of the string by index range.

Flashcard 51: What is the result of '"abc".concat("xyz");'?

Answer: "abcxyz". Concatenation combines strings into single result.

Flashcard 52: Which method returns a character array representing the string?

Answer: toCharArray(). Converts string into array of individual characters.

Flashcard 53: What is the result of '"Hello".equalsIgnoreCase("hello");'?

Answer: true. Case-insensitive comparison returns true for same content.

Flashcard 54: Find and correct the error: 'String s = new String("hello").toLowerCase();'

Answer: Correct: 'String s = "hello".toLowerCase();'. String literals don't need 'new String()' constructor.

Flashcard 55: What method returns a substring from a string in Java?

Answer: substring(). Extracts a portion of the string by index range.

Flashcard 56: What method checks if a string is empty in Java?

Answer: isEmpty(). Returns true if string length is zero.

Flashcard 57: What method returns the last index of a character in a string?

Answer: lastIndexOf(). Returns position of final occurrence of specified character.

Flashcard 58: Identify the method to trim whitespace from both ends of a string.

Answer: trim(). Removes leading and trailing whitespace characters.

Flashcard 59: What method checks if a string is empty in Java?

Answer: isEmpty(). Returns true if string length is zero.

Flashcard 60: Which method returns a string representation of an object?

Answer: toString(). Converts any object to its string representation.

Flashcard 61: Which method checks if a string starts with a specific prefix?

Answer: startsWith(). Tests if the string begins with specified text.

Flashcard 62: What is the output of '"Java".substring(1, 2);'?

Answer: "a". Extracts single character from index 1 to 2 (exclusive).