Method Description Example
charAt(int index) Returns the character at the specified index. String str = "Hello"; char result = [Link](1); result
will be 'e'
length() Returns the length of the string. String str = "Hello"; int length = [Link](); length will
be 5
concat(String str) Concatenates the specified string to the end of the current String str1 = "Hello"; String str2 = " World"; String result
string. = [Link](str2);
equals(Object obj) Compares the content of two strings. String str1 = "Hello"; String str2 = "hello"; boolean
isEqual = [Link](str2);
equalsIgnoreCase(String Compares two strings, ignoring case differences. String str1 = "Hello"; String str2 = "hello"; boolean
anotherString) isEqual = [Link](str2);
indexOf(int ch) Returns the index of the first occurrence of the specified String str = "Hello"; int index = [Link]('l'); index
character. will be 2
lastIndexOf(int ch) Returns the index of the last occurrence of the specified String str = "Hello"; int lastIndex = [Link]('l');
character. lastIndex will be 3
indexOf(int ch, int fromIndex) Returns the index of the first occurrence of the specified String str = "Hello"; int index = [Link]('l', 3); index
character, starting the search at the specified index. will be 3
lastIndexOf(int ch, int fromIndex) Returns the index of the last occurrence of the specified String str = "Hello"; int lastIndex = [Link]('l', 2);
character, searching backward from the specified index. lastIndex will be 2
substring(int beginIndex) Returns a new string that is a substring of the original string. String str = "Hello"; String subStr = [Link](2);
subStr will be "llo"
substring(int beginIndex, int Returns a new string that is a substring of the original string, String str = "Hello"; String subStr = [Link](2, 4);
endIndex) starting from the specified begin index and ending at the subStr will be "ll"
specified end index (exclusive).
toLowerCase() Converts all characters in the string to lowercase. String str = "Hello"; String lowerCaseStr =
[Link](); lowerCaseStr will be "hello"
toUpperCase() Converts all characters in the string to uppercase. String str = "Hello"; String upperCaseStr =
[Link](); upperCaseStr will be "HELLO"
trim() Removes leading and trailing whitespaces. String str = " Hello "; String trimmedStr = [Link]();
trimmedStr will be "Hello"
startsWith(String prefix) Checks if the string starts with the specified prefix. String str = "Hello"; boolean startsWithHello =
[Link]("Hello"); startsWithHello will be true
endsWith(String suffix) Checks if the string ends with the specified suffix. String str = "Hello"; boolean endsWithO =
[Link]("o"); endsWithO will be true
contains(CharSequence sequence) Checks if the string contains the specified sequence of String str = "Hello"; boolean containsL =
characters. [Link]("L"); containsL will be false
replace(char oldChar, char Replaces all occurrences of a specified character with String str = "Hello"; String replacedStr = [Link]('l',
newChar) another character. 'L'); replacedStr will be "HeLLo"
replace(CharSequence target, Replaces all occurrences of a specified sequence of String str = "Hello"; String replacedStr = [Link]("l",
CharSequence replacement) characters with another sequence. "L"); replacedStr will be "HeLLo"
replaceFirst(String regex, String Replaces the first substring of the string that matches the String str = "Hello Hello"; String replacedStr =
replacement) given regular expression with the specified replacement. [Link]("He", "She"); replacedStr will be "Shello
Hello"
replaceAll(String regex, String Replaces each substring of the string that matches the given String str = "Hello 123"; String replacedStr =
replacement) regular expression with the specified replacement. [Link]("\\d", "X"); replacedStr will be "Hello
XXX"
matches(String regex) Checks if the entire string matches the specified regular String str = "Hello"; boolean matches = [Link]("[A-
expression. Za-z]+"); matches will be true
split(String regex) Splits the string into an array of substrings based on the String str = "Hello World"; String[] parts = [Link]("\\
specified regular expression. s+"); parts will be ["Hello", "World"]
split(String regex, int limit) Splits the string into an array of substrings based on the String str = "Hello World Java"; String[] parts =
specified regular expression, with a specified limit. [Link]("\\s", 2); parts will be ["Hello", "World Java"]
toCharArray() Converts the string to a character array. String str = "Hello"; char[] charArray =
[Link](); charArray will be ['H', 'e', 'l', 'l', 'o']
getBytes() Encodes the string into a sequence of bytes using the String str = "Hello"; byte[] byteArray = [Link]();
platform's default charset. byteArray will contain the encoded bytes
valueOf(primitive data type x) Converts different types of values into a string. int num = 42; String str = [Link](num); str will
be "42"