The class String includes various Java String methods or functions for examining individual characters in a string. The Java String Methods perform string comparison, search, copy, extracting substring, and converting to lowercase or uppercase.
Java String methods
The following table shows the list of Java Methods or functions available in the String Class
Modifier Type | Methods | Description |
---|---|---|
char | chartAt(int index) | It returns the Character at the specified index position |
int | codePointAt(int index) | This returns the Unicode of the Character at a 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 the specified index position |
int | comapreTo(String str) | It compares two string lexicographical |
int | comapreToIgnoreCase(String str) | This Java 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 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) | 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) | It tests 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 functions return 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 functions convert 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 is 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 is 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 is 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 is not found |
String | intern() | This Java 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 is 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 is 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 is not found |
int | length() | This returns the length of this string |
boolean | matches(String regexp) | This Java 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 Methods test if two string regions are equal or not |
boolean | regionMatches(boolean ignorecase, int toffset, String other, int offset, int len) | It tests 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 a specified substring and then replaces all the occurrences of the Old_sequence substring with the new New_sequence substring. |
String | replaceAll(String regexp, String replacement) | This Method searches for a specified regular expression. Then replace all the occurrences of the 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 the 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 one 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 converts the given string into an Array of Characters or Character Array |
int | toLowerCase() | It converts the given string into Lowercase letters using the 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 converts the given value into a 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 removes the white spaces from both ends |
static String | ValueOf(boolean number) | Returns the string representation of the Boolean value |
“ | ValueOf(char character) | String representation of char |
“ | ValueOf(char[] myArray) | String representation of a character array |
“ | ValueOf(char[] myArray, int Offset, int count) | This returns the string representation of a subset character array. |
“ | ValueOf(double number) | String representation of Double value |
“ | ValueOf(float number) | String representation of Float value |
“ | ValueOf(int number) | It returns the string representation of the Integer value. |
“ | ValueOf(long number) | This Java method returns the string representation of the Long value. |
“ | ValueOf(Object obj) | String representation of an Object. |