10 Less Frequent Used Java String Methods

Sharangdhar Shree
2 min readJan 22, 2023
  1. The codePointAt() method returns the Unicode value of the character at the specified index in a string. The index of the first character is 0, the second character is 1, and so on.
  2. The codePointBefore() method returns the Unicode value of the character before the specified index in a string. The index of the first character is 1, the second character is 2, and so on. Note: The value 0 will generate an error, as this is a negative number (out of reach).
  3. The Java String class endsWith() method checks if this string ends with a given suffix. It returns true if this string ends with the given suffix; else returns false.
  4. The trim() method in Java String is a built-in function that eliminates leading and trailing spaces. The Unicode value of the space character is ‘\u0020’. The trim() method in java checks this Unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.
  5. The valueOf method returns the relevant Number Object holding the value of the argument passed. The argument can be a primitive data type, String, etc. This method is a static method. The method can take two arguments, where one is a String and the other is a radix.
  6. The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.
  7. The contentEquals() method searches a string to find out if it contains the exact same sequence of characters in the specified string or StringBuffer. Returns true if the characters exist and false if not.
  8. The Java String class intern() method returns the interned string. It returns the canonical representation of the string. It can be used to return a string from memory if it is created by a new keyword. It creates an exact copy of the heap string object in the String Constant Pool.
  9. The Character.offsetByCodePoints(CharSequence seq, int index, int codePointOffset) is an inbuilt method in java that returns the index within the given char sequence that is offset from the given index by codePointOffset code points.
  10. The regionMatches() method of the String class has two variants that can be used to test if two string regions are matching or are equal. There are two variants of this method, i.e., one is case sensitive test method, and the other ignores the case-sensitive method.

--

--