String Class Methods List

Here is a list of some commonly used methods of the String class:

  1. length(): Returns the length of the string.

  2. charAt(int index): Returns the character at the specified index.

  3. substring(int beginIndex, int endIndex): Returns a new string that is a substring of this string.

  4. concat(String str): Concatenates the specified string to the end of this string.

  5. equals(Object obj): Compares this string to the specified object for equality.

  6. compareTo(String anotherString): Compares this string to another string.

  7. toLowerCase(): Converts all of the characters in this string to lower case.

  8. toUpperCase(): Converts all of the characters in this string to upper case.

  9. trim(): Returns a new string that is a copy of this string with leading and trailing white space removed.

  10. indexOf(int ch): Returns the index within this string of the first occurrence of the specified character.

  11. lastIndexOf(int ch): Returns the index within this string of the last occurrence of the specified character.

  12. contains(CharSequence s): Returns true if this string contains the specified sequence of char values.

  13. replace(char oldChar, char newChar): Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

  14. startsWith(String prefix): Tests if this string starts with the specified prefix.

  15. endsWith(String suffix): Tests if this string ends with the specified suffix.

  16. split(String regex): Splits this string around matches of the given regular expression.

  17. toCharArray(): Converts this string to a new character array.

  18. valueOf(int i): Returns the string representation of the int argument.

  19. format(String format, Object... args): Returns a formatted string using the specified format string and arguments.

  20. isEmpty(): Returns true if this string is empty.

These methods can be used to manipulate and extract information from strings in various ways. Some methods are used for simple operations such as finding the length of a string, while others are used for more complex operations such as searching for and replacing substrings within a string.