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 Type | Java String Methods | Description of the java string Functions |
---|---|---|
char | chartAt(int index) | It returns the Character at specified index position |
int | codePointAt(int index) | This Java String Method returns the Unicode of the Character at specified index position |
int | codePointBefore(int index) | It returns the Unicode of the Character before the specified index position |
int | codePointCount(int start_index, int end_index) | It returns the Unicode of the Character at specified index position |
int | comapreTo(String str) | This Java String Method compares two string lexicographical |
int | comapreToIgnoreCase(String str) | This method compares two strings lexicographically. While comparing, this method ignores the case difference. |
String | concat(String str) | This method helps to Join the user-specified string to the end of the string and return the new string. |
boolean | contains(CharSequence s) | This Java String method returns TRUE if and only if the string contains the user-specified sequence of characters. |
boolean | contentEquals(CharSequence s) | It compares the string with the user specified sequence of characters |
boolean | contentEquals(StringBuffer sb) | It compares the string with the user-specified StringBuffer |
Static String | copyValueOf(char[] anCharArray) | This Java String method returns the string that represents the character sequence in the specified array. |
Static String | copyValueOf(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. |
boolean | endsWith(String suffix) | This Java string function test whether the string is ending with the suffix that we specified or not |
boolean | equals(Object anObject) | It compares this string with the user specified object |
Boolean | equalsIgnoreCase(String another_String) | It compares this string with the user-specified string (another_String). Note, while comparing, it ignores the case sensitivity. |
static String | format (String format, Object.. args) | Java string function returns a formatted string using the user specified format and arguments |
static String | format (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. |
int | hashCode() | It returns the Hash code of the Java string |
int | indexOf(int ch) | It returns the index position of the first occurrence of a specified character. It returns -1 if the specified character not found |
int | indexOf(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 |
int | indexOf(String str) | It returns the index position of the first occurrence of a specified substring. It returns -1 if the specified string not found |
int | indexOf(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 |
String | intern() | This function returns the canonical representation for the String Object |
boolean | isEmpty() | This function returns TRUE if the length of this string is Zero |
int | lastIndexOf(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 |
int | lastIndexOf(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 |
int | lastIndexOf(String str) | It returns the index position of the last occurrence of a given character. It returns -1 if the specified character not found |
int | lastIndexOf(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 |
int | length() | This Java String method returns the length of this string |
boolean | matches(String regexp) | This function tells whether this string matches a user-specified regular expression or not. |
int | offsetByCodePoints(int index, int codePointOffset) | It returns the index within the string that is offset of a given index by codePointOffset code points |
boolean | regionMatches(int toffset, String other, int offset, int len) | This Java String Method test if two string regions are equal or not |
boolean | regionMatches(boolean ignorecase, int toffset, String other, int offset, int len) | It test if two string regions are equal or not |
String | replace(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 |
String | replace(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. |
String | replaceAll(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. |
String | replaceFirst(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 |
boolean | startsWith(String prefix) | It tests whether the string is starting with the prefix that we specified or not |
boolean | startsWith(String prefix, int limit) | It tests whether the substring of this string is starting with the prefix that we specified or not |
CharSequence | subsequent(int Starting_Index, int End_Index) | This Java String Method returns a new sequence that is after the given sequence. |
String | substring(int Starting_Index) | It extracts the characters from a string based on the specified indices |
String | substring(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 |
int | toLowerCase() | It converts the given string into Lowercase letters using default locale |
String | toLowerCase(Locale locale) | It converts the given string into Lowercase letters, by considering the user-specified locale |
String | toString() | This Java String Method convert the given value into String Object |
String | toUpperCase() | It converts the given string into Uppercase letters |
String | toUpperCase(Locale locale) | It converts the given string into Uppercase letters, by considering the host environment’s current locale |
string | trim() | This Java String Method removes the white spaces from both ends |
static String | ValueOf(boolean number) | Returns the string representation of Boolean value |
static String | ValueOf(char character) | This Java string method returns the string representation of char |
static String | ValueOf(char[] myArray) | Returns the string representation of a character array |
static String | ValueOf(char[] myArray, int Offset, int count) | This Java String Method returns the string representation of a subset character array |
static String | ValueOf(double number) | Returns the string representation of Double value |
static String | ValueOf(float number) | Returns the string representation of Float value |
static String | ValueOf(int number) | Java String Method returns the string representation of Integer value |
static String | ValueOf(long number) | This Java String function returns the string representation of Long value |
static String | ValueOf(Object obj) | Returns the string representation of an Object. |