Implementing String Algorithms - AP Computer Science A

  1. How do you concatenate two strings in Java?
    Use the concat() method or the + operator. Both create a new string by joining the original strings.
  2. Identify the method to convert a double to a string in Java.
    Use Double.toString(). Converts the double value into its string representation.
  3. What method checks if a string starts with a specified prefix in Java?
    The method is startsWith(). Returns true if the string begins with the given prefix.
  4. What method checks if a string contains a specific sequence in Java?
    The method is contains(). Returns true if the specified character sequence exists within the string.
  5. Which method in Java checks if a string ends with a given suffix?
    The method is endsWith(). Returns true if the string concludes with the specified suffix.
  6. Find the method to convert a string representation of a number to an integer.
    Use Integer.parseInt(). Parses the string and returns the equivalent integer value.
  7. What method converts a string to a char array in Java?
    The method is toCharArray(). Creates a character array containing all the string's characters.
  8. Which method converts a string to uppercase in Java?
    The method is toUpperCase(). Creates a new string with all lowercase letters converted to uppercase.
  9. What method checks if a string is empty in Java?
    The method is isEmpty(). Returns true if the string has zero length.
  10. Find the method that returns a substring from a string in Java.
    The method is substring(). Extracts a portion of the string based on index parameters.
  11. What method converts a string to lowercase in Java?
    The method is toLowerCase(). Creates a new string with all uppercase letters converted to lowercase.
  12. What method in Java checks if a string contains a specific character?
    Use the contains() method. Returns true if the character sequence exists within the string.
  13. Identify the method that trims whitespace from a string in Java.
    The method is trim(). Removes leading and trailing whitespace characters.
  14. Identify the method to compare two strings in a case-insensitive manner.
    The method is equalsIgnoreCase(). Compares strings for equality without considering case differences.
  15. What method splits a string into an array in Java?
    The method is split(). Divides the string based on a delimiter into string array elements.
  16. Which method compares two strings ignoring case in Java?
    The method is equalsIgnoreCase(). Compares strings for equality without considering case differences.
  17. Which method converts a string representation of a number to a double?
    Use Double.parseDouble(). Parses the string and returns the equivalent double value.
  18. Identify the method to find the first occurrence of a character in a string.
    The method is indexOf(). Returns the index where the character first appears in the string.
  19. Which method returns a string representation of an object in Java?
    Use the toString() method. Returns the string representation of any object instance.
  20. What method returns the length of a string in Java?
    The method is length(). Returns the number of characters in the string.
  21. What method finds the last occurrence of a character in a string?
    The method is lastIndexOf(). Returns the index of the final occurrence of the character.
  22. Which method replaces characters in a string in Java?
    The method is replace(). Creates a new string with specified characters substituted.
  23. Which method checks if two strings are equal in Java?
    The method is equals(). Returns true if both strings have identical character sequences.
  24. Which method returns the character at a specific index in a string?
    The method is charAt(). Returns the character at the specified position in the string.
  25. Identify the method to compare two strings lexicographically in Java.
    The method is compareTo(). Returns an integer based on alphabetical ordering comparison.
  26. What is the method to convert an integer to a string in Java?
    Use Integer.toString(). Converts the integer value into its string representation.

Study these flashcards