Java String Functions

The class String includes various Java String methods or functions for examining individual characters in a string. The Java String Methods perform string comparison, string search, string copy, extracting substring, and convert string to lowercase or uppercase.

Java String Functions

The following table shows the list of Java String Method available in String Class

Modifier and TypeJava String MethodsDescription of the java string Functions
charchartAt(int index)It returns the Character at specified index position
intcodePointAt(int index)This Java String Method returns the Unicode of the Character at specified index position
intcodePointBefore(int index)It returns the Unicode of the Character before the specified index position
intcodePointCount(int start_index, int end_index)It returns the Unicode of the Character at specified index position
intcomapreTo(String str)This Java String Method compares two string lexicographical
intcomapreToIgnoreCase(String str)This method compares two strings lexicographically. While comparing, this method ignores the case difference.
Stringconcat(String str)This method helps to Join the user-specified string to the end of the string and return the new string.
booleancontains(CharSequence s)This Java String method returns TRUE if and only if the string contains the user-specified sequence of characters.
booleancontentEquals(CharSequence s)It compares the string with the user specified sequence of characters
booleancontentEquals(StringBuffer sb)It compares the string with the user-specified StringBuffer
Static StringcopyValueOf(char[] anCharArray)This Java String method returns the string that represents the character sequence in the specified array.
Static StringcopyValueOf(char[] anCharArray, int offset, int count)This method returns the string that represents the character sequence in the specified array, starting at offset until it reaches the specified count.
booleanendsWith(String suffix)This Java string function test whether the string is ending with the suffix that we specified or not
booleanequals(Object anObject)It compares this string with the user specified object
BooleanequalsIgnoreCase(String another_String)It compares this string with the user-specified string (another_String). Note, while comparing, it ignores the case sensitivity.
static Stringformat (String format, Object.. args)Java string function returns a formatted string using the user specified format and arguments
static Stringformat (locale l, String format, Object.. args)

It returns a formatted string using the user-specified locale, format, and arguments

byte[]getBytes()It converts the string into a sequence of bytes using the platform default charset and stores it in a byte array.
byte[]getBytes(Charset charset)It converts the given string into a sequence of bytes using the specified charset and stores it in a byte array
byte[]getBytes(String charset_Name)This Java string function converts the string into a sequence of bytes using the named charset and stores it in a byte array.
inthashCode()It returns the Hash code of the Java string
intindexOf(int ch)It returns the index position of the first occurrence of a specified character. It returns -1 if the specified character not found
intindexOf(int ch, int Starting_Index)It returns the index position of the first occurrence of a given character. It returns -1 if the specified character not found
intindexOf(String str)It returns the index position of the first occurrence of a specified substring. It returns -1 if the specified string not found
intindexOf(String str, int Start_Index)It returns the index position of the first occurrence of a specified substring. It returns -1 if the specified string not found
Stringintern()This function returns the canonical representation for the String Object
booleanisEmpty()This function returns TRUE if the length of this string is Zero
intlastIndexOf(int ch)It returns the index position of the last occurrence of a specified character. It returns -1 if the given character is not found
intlastIndexOf(int ch, int End_Index)Returns the index position of the last occurrence of a specified character. It returns -1 if the specified character not found
intlastIndexOf(String str)It returns the index position of the last occurrence of a given character. It returns -1 if the specified character not found
intlastIndexOf(String str, int End_Index)Returns the index position of the last occurrence of a specified character. It returns -1 if the given character not found
intlength()This Java String method returns the length of this string
booleanmatches(String regexp)This function tells whether this string matches a user-specified regular expression or not.
intoffsetByCodePoints(int index, int codePointOffset)It returns the index within the string that is offset of a given index by codePointOffset code points
booleanregionMatches(int toffset, String other, int offset, int len)This Java String Method test if two string regions are equal or not
booleanregionMatches(boolean ignorecase, int toffset, String other, int offset, int len)It test if two string regions are equal or not
Stringreplace(char Old_Character, char New_Character)This Java string function search for specified character and then replace all the occurrences of Old_Character with new New_Character
Stringreplace(CharSequence Old_sequence, CharSequence New_sequence)It searches for specified substring and then replaces all the occurrences of Old_sequence substring with new New_sequence substring.
StringreplaceAll(String regexp, String replacement)This Java String Method searches for a specified regular expression. Then replace all the occurrences of regular expression substring with the given replacement substring.
StringreplaceFirst(String regexp, String replacement)

It searches for a specified regular expression and then replaces the first occurrence of regular expression substring with the given replacement substring

String[]split(String regex)It Split the string into an Array of Substrings based on the separator we specified
String[]split(String regex, int limit)This Java String Method Split the string into an Array of Substrings based on the separator we specified
booleanstartsWith(String prefix)It tests whether the string is starting with the prefix that we specified or not
booleanstartsWith(String prefix, int limit)It tests whether the substring of this string is starting with the prefix that we specified or not
CharSequencesubsequent(int Starting_Index, int End_Index)This Java String Method returns a new sequence that is after the given sequence.
Stringsubstring(int Starting_Index)It extracts the characters from a string based on the specified indices
Stringsubstring(int Starting_Index, int End_Index)It extracts the characters from a string based on the specified starting position and end position.
char[]toCharArray()This Java String Method convert the given string into an Array of Characters or Character Array
inttoLowerCase()It converts the given string into Lowercase letters using default locale
StringtoLowerCase(Locale locale)It converts the given string into Lowercase letters, by considering the user-specified locale
StringtoString()This Java String Method convert the given value into String Object
StringtoUpperCase()It converts the given string into Uppercase letters
StringtoUpperCase(Locale locale)It converts the given string into Uppercase letters, by considering the host environment’s current locale
stringtrim()This Java String Method removes the white spaces from both ends
static StringValueOf(boolean number)Returns the string representation of Boolean value
static StringValueOf(char character)This Java string method returns the string representation of char
static StringValueOf(char[] myArray)Returns the string representation of a character array
static StringValueOf(char[] myArray, int Offset, int count)This Java String Method returns the string representation of a subset character array
static StringValueOf(double number)Returns the string representation of Double value
static StringValueOf(float number)Returns the string representation of Float value
static StringValueOf(int number)Java String Method returns the string representation of Integer value
static StringValueOf(long number)This Java String function returns the string representation of Long value
static StringValueOf(Object obj)Returns the string representation of an Object.