The String class in Java has many built-in methods to manipulate and work with strings. Some common string methods include charAt() to return the character at a specific index, length() to return the length of the string, concat() to concatenate two strings, indexOf() to find the index of a substring, and toLowerCase() to convert a string to lowercase.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
22 views
String Methods
The String class in Java has many built-in methods to manipulate and work with strings. Some common string methods include charAt() to return the character at a specific index, length() to return the length of the string, concat() to concatenate two strings, indexOf() to find the index of a substring, and toLowerCase() to convert a string to lowercase.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
String Methods:
The String class has a set of built-in methods that you can use on strings.
Method Description Return Type
Returns the character at the specified index (position) charAt() char Returns the Unicode of the character at the specified codePointAt() int index Returns the Unicode of the character before the codePointBefore() int specified index Returns the number of Unicode values found in a codePointCount() int string. compareTo() Compares two strings lexicographically int Compares two strings lexicographically, ignoring case compareToIgnoreCase() int differences concat() Appends a string to the end of another string String Checks whether a string contains a sequence of contains() boolean characters Checks whether a string contains the exact same contentEquals() sequence of characters of the specified CharSequence boolean or StringBuffer Returns a String that represents the characters of the copyValueOf() String character array Checks whether a string ends with the specified endsWith() boolean character(s) Compares two strings. Returns true if the strings are equals() boolean equal, and false if not equalsIgnoreCase() Compares two strings, ignoring case considerations boolean Returns a formatted string using the specified locale, format() String format string, and arguments Encodes this String into a sequence of bytes using the getBytes() named charset, storing the result into a new byte byte[] array getChars() Copies characters from a string to an array of chars void hashCode() Returns the hash code of a string int Returns the position of the first found occurrence of indexOf() int specified characters in a string Returns the canonical representation for the string intern() String object isEmpty() Checks whether a string is empty or not boolean Returns the position of the last found occurrence of lastIndexOf() int specified characters in a string length() Returns the length of a specified string int Searches a string for a match against a regular matches() boolean expression, and returns the matches Returns the index within this String that is offset from offsetByCodePoints() int the given index by codePointOffset code points regionMatches() Tests if two string regions are equal boolean Searches a string for a specified value, and returns a replace() String new string where the specified values are replaced Replaces the first occurrence of a substring that replaceFirst() matches the given regular expression with the given String replacement Replaces each substring of this string that matches the replaceAll() String given regular expression with the given replacement split() Splits a string into an array of substrings String[] Checks whether a string starts with specified startsWith() boolean characters Returns a new character sequence that is a subSequence() CharSequence subsequence of this sequence Returns a new string which is the substring of a substring() String specified string toCharArray() Converts this string to a new character array char[] toLowerCase() Converts a string to lower case letters String toString() Returns the value of a String object String toUpperCase() Converts a string to upper case letters String trim() Removes whitespace from both ends of a string String Returns the string representation of the specified valueOf() String value