Additional String Methods


In addition to these methods discussed earlier, there are many more methods of string. Summarized in several of the following tables:

Method Description
int codePointAt(int j) Returns the Unicode code point at the location specified by j.
int codePointBefore(int j) Return the Unicode code point at the location that precedes that specified by j.
int codePointCount(int s, int e) Returns the nubmer of code points in the portion of the invoking String that are between s and e -1.
boolean contains(CharSequence s) Returns true if the invoking ojbect contains the string specified by str. Returns false otherwise.
boolean contentEquals(CharSequence s) Returns true if the invoking string contains the same string as s. Otherwise, returns false.
boolean contentEquals(StringBuffer s) Returns true if the invoking string contains the same string as s. Otherwise, returns false.
static String format(String f, Object ... args) Returns a string formatted as specified by f.
static String format(Locale loc, String f, Object ... args) Returns a string formatted as specified by f. Formatting is governed by the locale specified by loc.
boolean isEmpty() Returns true if the invoking string contains no characters and has a length of zero.
boolean matches(String reg) Returns true if the invoking string matches the regular expression passed in reg. Otherwise, returns false.
int offsetByCodePoints(int s, int n) Returns the index within the invoking string that is n code points beyond the starting index specified by s.
String replaceFirst(String reg, String new) Returns a string in which the first substring that matches the regular expression specified by reg is replaced by new.
String replaceAll(String reg,String new) Returns a string in which all substrings that match the regular expression specified by reg are replaced by new.
String [] split(String reg) Decomposes the invoking string into parts and returns an array that contains the result. Each part is delimited by the regular expression passed reg
String [] split(String reg, int m) Decomposes the invoking string into parts and returns an array that contains the result. Each part is delimited of the regular expression passed in reg, The number of pieces is specified by m. If m is negative, then the invoking string is fully decomposed. Otherwise, if m contains a nonzero values, the last entry in the returned array contains the remainder of the invoking string. If max is zero, the invoking string fully decomposed, but no trialing empty strings will be included.
CharSequence subSequence(int start, int stop) Returns a substrings of the invoking string, beginning at start and stopping at stop. This method is required by the CharSequence interface, which is implemented by String.