Java String Functions
Method Return Type Arguments Description
length() int None Returns the length
of the string.
charAt(int index) char index (int) Returns the
character at the
given index.
substring(int String beginIndex (int) Returns substring
beginIndex) from given index to
end.
substring(int String beginIndex (int), Returns substring
beginIndex, int endIndex (int) from beginIndex to
endIndex) endIndex-1.
indexOf(char ch) int ch (char) Returns the index of
the first occurrence
of the character.
indexOf(String str) int str (String) Returns the index of
the first occurrence
of the substring.
lastIndexOf(char ch) int ch (char) Returns the last
occurrence of the
character.
toLowerCase() String None Converts the string
to lowercase.
toUpperCase() String None Converts the string
to uppercase.
trim() String None Removes leading
and trailing spaces.
replace(char String oldChar (char), Replaces
oldChar, char newChar (char) occurrences of a
newChar) character.
replace(String String oldStr (String), Replaces
oldStr, String newStr (String) occurrences of a
newStr) substring.
equals(String boolean anotherString Compares two
anotherString) (String) strings (case-
sensitive).
equalsIgnoreCase(St boolean anotherString Compares two
ring anotherString) (String) strings (case-
insensitive).
startsWith(String boolean prefix (String) Checks if the string
prefix) starts with the given
prefix.
endsWith(String boolean suffix (String) Checks if the string
suffix) ends with the given
suffix.
contains(CharSeque boolean sequence Checks if the string
nce sequence) (CharSequence) contains the given
sequence.
split(String regex) String[] regex (String) Splits the string
based on a regular
expression.
concat(String str) String str (String) Concatenates (joins)
two strings.
compareTo(String int anotherString Compares two
anotherString) (String) strings
lexicographically.
compareToIgnoreCa int anotherString Compares two
se(String (String) strings
anotherString) lexicographically
(case-insensitive).