String Methods in Java

String Methods in Java

The String class has a set of built-in methods that you can use on strings.


String Methods in Java



 The String class Methods:


1. Method Description (Return Type)


2. charAt() Returns the character at the specified index (position) (char)


3. codePointAt() Returns the Unicode of the character at the specified index (int)


4. codePointBefore() Returns the Unicode of the character before the specified index (int)


5. codePointCount() Returns the Unicode in the specified text range of this String (int)


6. compareTo() Compares two strings lexicographically (int)


7. compareToIgnoreCase() Compares two strings lexicographically, ignoring case differences (int)


8. concat() Appends a string to the end of another string (String)


9. contains() Checks whether a string contains a sequence of characters (boolean)


10. contentEquals() Checks whether a string contains the exact same sequence of characters of the specified CharSequence or StringBuffer (boolean)


11. copyValueOf() Returns a String that represents the characters of the character array (String)


12. endsWith() Checks whether a string ends with the specified character(s) (boolean)


13. equals() Compares two strings. Returns true if the strings are equal, and false if not (boolean)


14. equalsIgnoreCase() Compares two strings, ignoring case considerations (boolean)


15. format() Returns a formatted string using the specified locale, format string, and arguments (String)


16. getBytes() Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array (byte[])


17. getChars() Copies characters from a string to an array of chars (void)


18. hashCode() Returns the hash code of a string (int)


19. indexOf() Returns the position of the first found occurrence of specified characters in a string (int)


20. intern() Returns the canonical representation for the string object (String)


21. isEmpty() Checks whether a string is empty or not (boolean)


22. lastIndexOf() Returns the position of the last found occurrence of specified characters in a string (int)


23. length() Returns the length of a specified string (int)


24. matches() Searches a string for a match against a regular expression and returns the matches (boolean)


25. offsetByCodePoints() Returns the index within this String that is offset from the given index by codePointOffset code points (int)


26. regionMatches() Tests if two string regions are equal (boolean)


27. replace() Searches a string for a specified value, and returns a new string where the specified values are replaced (String)


28. replaceFirst() Replaces the first occurrence of a substring that matches the given regular expression with the given replacement (String)


29. replaceAll() Replaces each substring of this string that matches the given regular expression with the given replacement (String)


30. split() Splits a string into an array of substrings (String[])


31. startsWith() Checks whether a string starts with specified characters (boolean)


32. subSequence() Returns a new character sequence that is a subsequence of this sequence (CharSequence)


33. substring() Extracts the characters from a string, beginning at a specified start position, and through the specified number of character (String)


34. toCharArray() Converts this string to a new character array (char[])


35. toLowerCase() Converts a string to lower case letters (String)


36. toString() Returns the value of a String object (String)


37. toUpperCase() Converts a string to upper case letters (String)


38. trim() Removes whitespace from both ends of a string (String)


39. valueOf() Returns the string representation of the specified value  (String)



No comments:

For Query and doubts!

Powered by Blogger.