Core APIs Flashcards
STRING: int length()
Returns the length of the string
STRING: char charAt(int index)
Returns the character at the specified index in the string.
STRING: int indexOf(int ch, int fromIndex)
Returns the index of the first occurrence of the specified character, starting the search at fromIndex.
STRING: int indexOf(String str)
Returns the index of the first occurrence of the specified substring.
STRING: String substring(int beginIndex)
Returns a new string that is a substring of this string, starting from beginIndex to the end.
STRING: int indexOf(String str, int fromIndex)
Returns the index of the first occurrence of the specified substring, starting the search at fromIndex.
STRING: String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string, starting from beginIndex and ending at endIndex - 1.
STRING: String toLowerCase()
Converts all characters in the string to lowercase.
STRING: String toUpperCase()
Converts all characters in the string to uppercase.
STRING: boolean equals(Object obj)
Compares this string to the specified object for equality.
STRING: boolean startsWith(String prefix)
Tests if this string starts with the specified prefix.
STRING: boolean equalsIgnoreCase(String str)
Compares this string to another string, ignoring case considerations.
STRING: boolean endsWith(String suffix)
Tests if this string ends with the specified suffix.
STRING: boolean contains(CharSequence charSeq)
Returns true if and only if this string contains the specified sequence of characters.
STRING: String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
STRING: String replace(CharSequence target, CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified replacement sequence.
How to return the length of the string?
int length()
How to get the character at a specific index in the string?
char charAt(int index)
How to find the index of a character, starting the search from a specific index?
int indexOf(int ch, int fromIndex)
How to find the index of the first occurrence of a substring?
int indexOf(String str)
How to find the index of a substring, starting the search from a specific index?
int indexOf(String str, int fromIndex)
How to get a substring from a specific index to the end of the string?
String substring(int beginIndex)
How to get a substring between two specified indices?
String substring(int beginIndex, int endIndex)
How to convert all characters in the string to lowercase?
String toLowerCase()
How to convert all characters in the string to uppercase?
String toUpperCase()
How to compare this string to another object for equality?
boolean equals(Object obj)
How to compare this string to another string, ignoring case?
boolean equalsIgnoreCase(String str)
How to check if a string starts with a specific prefix?
boolean startsWith(String prefix)
How to check if a string ends with a specific suffix?
boolean endsWith(String suffix)
How to check if a string contains a specific sequence of characters?
boolean contains(CharSequence charSeq)
How to replace all occurrences of a character with another character in a string?
String replace(char oldChar, char newChar)
How to replace all occurrences of a target sequence with a replacement sequence in a string?
String replace(CharSequence target, CharSequence replacement)
How to remove whitespace from both ends of a string?
String strip()
How to remove whitespace from the end of a string?
String stripTrailing()
How to remove whitespace from the beginning of a string?
String stripLeading()
How to add a specified number of spaces at the beginning of a string?
String indent(int numberSpaces)
How to remove whitespace from both ends of a string (alternative to strip())?
String trim()
How to remove leading whitespace from every line in a string?
String stripIndent()
How to return a string with escape sequences translated?
String translateEscapes()
How to check if a string is empty (length of 0)?
boolean isEmpty()
How to check if a string is empty or contains only whitespace characters?
boolean isBlank()
STRING: String stripLeading()
Removes whitespace from the beginning of the string.
How to create a formatted string using a format string and arguments?
static String format(String format, Object args…)
How to create a formatted string using a specific locale, format string, and arguments?
static String format(Locale loc, String format, Object args…)
STRING: String stripTrailing()
Removes whitespace from the end of the string.
How to create a formatted string using this string as the format string?
String formatted(Object args…)
STRING: String strip()
Removes whitespace from both the beginning and end of the string.
STRING: String trim()
Removes whitespace from both the beginning and end of the string (similar to strip()).
STRING: String indent(int numberSpaces)
Adds the specified number of spaces to the beginning of each line in the string. Can use negative numbers to remove spaces.
STRING: String translateEscapes()
Translates escape sequences in the string (like \n, \t) into their corresponding characters.