Module java.base
Package java.lang

Class String

    • Constructor Summary

      Constructors 
      Constructor Description
      String()
      Answers an empty string.
      String​(byte[] data)
      Converts the byte array to a String using the default encoding as specified by the file.encoding system property.
      String​(byte[] data, int high)
      Deprecated.
      Use String(byte[]) or String(byte[], String) instead
      String​(byte[] data, int start, int length)
      Converts the byte array to a String using the default encoding as specified by the file.encoding system property.
      String​(byte[] data, int high, int start, int length)
      Deprecated.
      Use String(byte[], int, int) instead
      String​(byte[] data, int start, int length, String encoding)
      Converts the byte array to a String using the specified encoding.
      String​(byte[] data, int start, int length, Charset charset)
      Converts the byte array to a String using the specified Charset.
      String​(byte[] data, String encoding)
      Converts the byte array to a String using the specified encoding.
      String​(byte[] data, Charset charset)
      Converts the byte array to a String using the specified Charset.
      String​(char[] data)
      Initializes this String to contain the characters in the specified character array.
      String​(char[] data, int start, int length)
      Initializes this String to contain the specified characters in the character array.
      String​(int[] data, int start, int length)  
      String​(String string)
      Creates a string that is a copy of another string
      String​(StringBuffer buffer)
      Creates a string from the contents of a StringBuffer.
      String​(StringBuilder builder)
      Creates a string from the contents of a StringBuilder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      char charAt​(int index)
      Answers the character at the specified offset in this String.
      int codePointAt​(int index)
      Returns the Unicode character at the given point.
      int codePointBefore​(int index)
      Returns the Unicode character before the given point.
      int codePointCount​(int start, int end)
      Returns the total Unicode values in the specified range.
      int compareTo​(String string)
      Compares the specified String to this String using the Unicode values of the characters.
      int compareToIgnoreCase​(String string)
      Compare the receiver to the specified String to determine the relative ordering when the case of the characters is ignored.
      String concat​(String string)
      Concatenates this String and the specified string.
      boolean contains​(CharSequence sequence)  
      boolean contentEquals​(CharSequence sequence)
      Compares the content of the character sequence to this String
      boolean contentEquals​(StringBuffer buffer)
      Answers whether the characters in the StringBuffer buffer are the same as those in this String.
      static String copyValueOf​(char[] data)
      Creates a new String containing the characters in the specified character array.
      static String copyValueOf​(char[] data, int start, int length)
      Creates a new String containing the specified characters in the character array.
      boolean endsWith​(String suffix)
      Compares the specified string to this String to determine if the specified string is a suffix.
      boolean equals​(Object object)
      Compares the specified object to this String and answer if they are equal.
      boolean equalsIgnoreCase​(String string)
      Compares the specified String to this String ignoring the case of the characters and answer if they are equal.
      static String format​(String format, Object... args)
      Format the receiver using the specified format and args.
      static String format​(Locale locale, String format, Object... args)
      Format the receiver using the specified local, format and args.
      byte[] getBytes()
      Converts this String to a byte encoding using the default encoding as specified by the file.encoding system property.
      void getBytes​(int start, int end, byte[] data, int index)
      Deprecated.
      Use getBytes() or getBytes(String)
      byte[] getBytes​(String encoding)
      Converts this String to a byte encoding using the specified encoding.
      byte[] getBytes​(Charset charset)
      Converts this String to a byte encoding using the specified Charset.
      void getChars​(int start, int end, char[] data, int index)
      Copies the specified characters in this String to the character array starting at the specified offset in the character array.
      int hashCode()
      Answers an integer hash code for the receiver.
      int indexOf​(int c)
      Searches in this String for the first index of the specified character.
      int indexOf​(int c, int start)
      Searches in this String for the index of the specified character.
      int indexOf​(String string)
      Searches in this String for the first index of the specified string.
      int indexOf​(String subString, int start)
      Searches in this String for the index of the specified string.
      String intern()
      Searches an internal table of strings for a string equal to this String.
      boolean isBlank()
      Determine if the string contains only white space characters.
      boolean isEmpty()
      Answers if this String has no characters, a length of zero.
      static String join​(CharSequence delimiter, CharSequence... elements)
      Creates a new String by putting each element together joined by the delimiter.
      static String join​(CharSequence delimiter, Iterable<? extends CharSequence> elements)
      Creates a new String by putting each element together joined by the delimiter.
      int lastIndexOf​(int c)
      Searches in this String for the last index of the specified character.
      int lastIndexOf​(int c, int start)
      Searches in this String for the index of the specified character.
      int lastIndexOf​(String string)
      Searches in this String for the last index of the specified string.
      int lastIndexOf​(String subString, int start)
      Searches in this String for the index of the specified string.
      int length()
      Answers the size of this String.
      Stream<String> lines()
      Returns a stream of substrings extracted from this string partitioned by line terminators.
      boolean matches​(String expr)
      Determines whether a this String matches a given regular expression.
      int offsetByCodePoints​(int start, int codePointCount)
      Returns the index of the code point that was offset by codePointCount.
      boolean regionMatches​(boolean ignoreCase, int thisStart, String string, int start, int length)
      Compares the specified string to this String and compares the specified range of characters to determine if they are the same.
      boolean regionMatches​(int thisStart, String string, int start, int length)
      Compares the specified string to this String and compares the specified range of characters to determine if they are the same.
      String repeat​(int count)
      Returns a string whose value is the concatenation of this string repeated count times.
      String replace​(char oldChar, char newChar)
      Replaces occurrences of the specified character with another character.
      String replace​(CharSequence sequence1, CharSequence sequence2)  
      String replaceAll​(String regex, String substitute)
      Replace any substrings within this String that match the supplied regular expression expr, with the String substitute.
      String replaceFirst​(String expr, String substitute)
      Replace any substrings within this String that match the supplied regular expression expr, with the String substitute.
      String[] split​(String regex)
      Splits this string around matches of the given regular expression.
      String[] split​(String regex, int max)
      Splits this String using the given regular expression.
      boolean startsWith​(String prefix)
      Compares the specified string to this String to determine if the specified string is a prefix.
      boolean startsWith​(String prefix, int start)
      Compares the specified string to this String, starting at the specified offset, to determine if the specified string is a prefix.
      String strip()
      Strip leading and trailing white space from a string.
      String stripLeading()
      Strip leading white space from a string.
      String stripTrailing()
      Strip trailing white space from a string.
      CharSequence subSequence​(int start, int end)
      Has the same result as the substring function, but is present so that String may implement the CharSequence interface.
      String substring​(int start)
      Copies a range of characters into a new String.
      String substring​(int start, int end)
      Copies a range of characters.
      char[] toCharArray()
      Copies the characters in this String to a character array.
      String toLowerCase()
      Converts the characters in this String to lowercase, using the default Locale.
      String toLowerCase​(Locale locale)
      Converts the characters in this String to lowercase, using the specified Locale.
      String toString()
      Answers a string containing a concise, human-readable description of the receiver.
      String toUpperCase()
      Converts the characters in this String to uppercase, using the default Locale.
      String toUpperCase​(Locale locale)
      Converts the characters in this String to uppercase, using the specified Locale.
      String trim()
      Removes white space characters from the beginning and end of the string.
      static String valueOf​(boolean value)
      Converts the specified boolean to its string representation.
      static String valueOf​(char value)
      Converts the specified character to its string representation.
      static String valueOf​(char[] data)
      Returns a String containing the characters in the specified character array.
      static String valueOf​(char[] data, int start, int length)
      Returns a String containing the specified characters in the character array.
      static String valueOf​(double value)
      Converts the specified double to its string representation.
      static String valueOf​(float value)
      Converts the specified float to its string representation.
      static String valueOf​(int value)
      Converts the specified integer to its string representation.
      static String valueOf​(long value)
      Converts the specified long to its string representation.
      static String valueOf​(Object value)
      Converts the specified object to its string representation.
    • Field Detail

      • CASE_INSENSITIVE_ORDER

        public static final Comparator<String> CASE_INSENSITIVE_ORDER
        A Comparator which compares Strings ignoring the case of the characters.
    • Method Detail

      • charAt

        public char charAt​(int index)
        Answers the character at the specified offset in this String.
        Specified by:
        charAt in interface CharSequence
        Parameters:
        index - the zero-based index in this string
        Returns:
        the character at the index
        Throws:
        IndexOutOfBoundsException - when index < 0 or index >= length()
      • compareTo

        public int compareTo​(String string)
        Compares the specified String to this String using the Unicode values of the characters. Answer 0 if the strings contain the same characters in the same order. Answer a negative integer if the first non-equal character in this String has a Unicode value which is less than the Unicode value of the character at the same position in the specified string, or if this String is a prefix of the specified string. Answer a positive integer if the first non-equal character in this String has a Unicode value which is greater than the Unicode value of the character at the same position in the specified string, or if the specified String is a prefix of the this String.
        Specified by:
        compareTo in interface Comparable<String>
        Parameters:
        string - the string to compare
        Returns:
        0 if the strings are equal, a negative integer if this String is before the specified String, or a positive integer if this String is after the specified String
        Throws:
        NullPointerException - when string is null
      • compareToIgnoreCase

        public int compareToIgnoreCase​(String string)
        Compare the receiver to the specified String to determine the relative ordering when the case of the characters is ignored.
        Parameters:
        string - a String
        Returns:
        an int < 0 if this String is less than the specified String, 0 if they are equal, and > 0 if this String is greater
      • concat

        public String concat​(String string)
        Concatenates this String and the specified string.
        Parameters:
        string - the string to concatenate
        Returns:
        a String which is the concatenation of this String and the specified String
        Throws:
        NullPointerException - if string is null
      • copyValueOf

        public static String copyValueOf​(char[] data)
        Creates a new String containing the characters in the specified character array. Modifying the character array after creating the String has no effect on the String.
        Parameters:
        data - the array of characters
        Returns:
        the new String
        Throws:
        NullPointerException - if data is null
      • copyValueOf

        public static String copyValueOf​(char[] data,
                                         int start,
                                         int length)
        Creates a new String containing the specified characters in the character array. Modifying the character array after creating the String has no effect on the String.
        Parameters:
        data - the array of characters
        start - the starting offset in the character array
        length - the number of characters to use
        Returns:
        the new String
        Throws:
        IndexOutOfBoundsException - when length < 0, start < 0 or start + length > data.length
        NullPointerException - if data is null
      • endsWith

        public boolean endsWith​(String suffix)
        Compares the specified string to this String to determine if the specified string is a suffix.
        Parameters:
        suffix - the string to look for
        Returns:
        true when the specified string is a suffix of this String, false otherwise
        Throws:
        NullPointerException - if suffix is null
      • equals

        public boolean equals​(Object object)
        Compares the specified object to this String and answer if they are equal. The object must be an instance of String with the same characters in the same order.
        Overrides:
        equals in class Object
        Parameters:
        object - the object to compare
        Returns:
        true if the specified object is equal to this String, false otherwise
        See Also:
        hashCode()
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(String string)
        Compares the specified String to this String ignoring the case of the characters and answer if they are equal.
        Parameters:
        string - the string to compare
        Returns:
        true if the specified string is equal to this String, false otherwise
      • getBytes

        public byte[] getBytes()
        Converts this String to a byte encoding using the default encoding as specified by the file.encoding system property. If the system property is not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1 is not available, an ASCII encoding is used.
        Returns:
        the byte array encoding of this String
        See Also:
        String
      • getBytes

        @Deprecated(forRemoval=false,
                    since="1.1")
        public void getBytes​(int start,
                             int end,
                             byte[] data,
                             int index)
        Deprecated.
        Use getBytes() or getBytes(String)
        Converts this String to a byte array, ignoring the high order bits of each character.
        Parameters:
        start - the starting offset of characters to copy
        end - the ending offset of characters to copy
        data - the destination byte array
        index - the starting offset in the byte array
        Throws:
        NullPointerException - when data is null
        IndexOutOfBoundsException - when start < 0, end > length(), index < 0, end - start > data.length - index
      • getChars

        public void getChars​(int start,
                             int end,
                             char[] data,
                             int index)
        Copies the specified characters in this String to the character array starting at the specified offset in the character array.
        Parameters:
        start - the starting offset of characters to copy
        end - the ending offset of characters to copy
        data - the destination character array
        index - the starting offset in the character array
        Throws:
        IndexOutOfBoundsException - when start < 0, end > length(), start > end, index < 0, end - start > buffer.length - index
        NullPointerException - when buffer is null
      • hashCode

        public int hashCode()
        Answers an integer hash code for the receiver. Objects which are equal answer the same value for this method.
        Overrides:
        hashCode in class Object
        Returns:
        the receiver's hash
        See Also:
        equals(java.lang.Object)
      • indexOf

        public int indexOf​(int c)
        Searches in this String for the first index of the specified character. The search for the character starts at the beginning and moves towards the end of this String.
        Parameters:
        c - the character to find
        Returns:
        the index in this String of the specified character, -1 if the character isn't found
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • indexOf

        public int indexOf​(int c,
                           int start)
        Searches in this String for the index of the specified character. The search for the character starts at the specified offset and moves towards the end of this String.
        Parameters:
        c - the character to find
        start - the starting offset
        Returns:
        the index in this String of the specified character, -1 if the character isn't found
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • indexOf

        public int indexOf​(String subString,
                           int start)
        Searches in this String for the index of the specified string. The search for the string starts at the specified offset and moves towards the end of this String.
        Parameters:
        subString - the string to find
        start - the starting offset
        Returns:
        the index in this String of the specified string, -1 if the string isn't found
        Throws:
        NullPointerException - when string is null
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • intern

        public String intern()
        Searches an internal table of strings for a string equal to this String. If the string is not in the table, it is added. Answers the string contained in the table which is equal to this String. The same string object is always answered for strings which are equal.
        Returns:
        the interned string equal to this String
      • lastIndexOf

        public int lastIndexOf​(int c)
        Searches in this String for the last index of the specified character. The search for the character starts at the end and moves towards the beginning of this String.
        Parameters:
        c - the character to find
        Returns:
        the index in this String of the specified character, -1 if the character isn't found
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • lastIndexOf

        public int lastIndexOf​(int c,
                               int start)
        Searches in this String for the index of the specified character. The search for the character starts at the specified offset and moves towards the beginning of this String.
        Parameters:
        c - the character to find
        start - the starting offset
        Returns:
        the index in this String of the specified character, -1 if the character isn't found
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • lastIndexOf

        public int lastIndexOf​(String subString,
                               int start)
        Searches in this String for the index of the specified string. The search for the string starts at the specified offset and moves towards the beginning of this String.
        Parameters:
        subString - the string to find
        start - the starting offset
        Returns:
        the index in this String of the specified string, -1 if the string isn't found
        Throws:
        NullPointerException - when string is null
        See Also:
        lastIndexOf(int), lastIndexOf(int, int), lastIndexOf(String), lastIndexOf(String, int)
      • length

        public int length()
        Answers the size of this String.
        Specified by:
        length in interface CharSequence
        Returns:
        the number of characters in this String
      • regionMatches

        public boolean regionMatches​(int thisStart,
                                     String string,
                                     int start,
                                     int length)
        Compares the specified string to this String and compares the specified range of characters to determine if they are the same.
        Parameters:
        thisStart - the starting offset in this String
        string - the string to compare
        start - the starting offset in string
        length - the number of characters to compare
        Returns:
        true if the ranges of characters is equal, false otherwise
        Throws:
        NullPointerException - when string is null
      • regionMatches

        public boolean regionMatches​(boolean ignoreCase,
                                     int thisStart,
                                     String string,
                                     int start,
                                     int length)
        Compares the specified string to this String and compares the specified range of characters to determine if they are the same. When ignoreCase is true, the case of the characters is ignored during the comparison.
        Parameters:
        ignoreCase - specifies if case should be ignored
        thisStart - the starting offset in this String
        string - the string to compare
        start - the starting offset in string
        length - the number of characters to compare
        Returns:
        true if the ranges of characters is equal, false otherwise
        Throws:
        NullPointerException - when string is null
      • replace

        public String replace​(char oldChar,
                              char newChar)
        Replaces occurrences of the specified character with another character.
        Parameters:
        oldChar - the character to replace
        newChar - the replacement character
        Returns:
        a String with occurrences of oldChar replaced by newChar
      • startsWith

        public boolean startsWith​(String prefix)
        Compares the specified string to this String to determine if the specified string is a prefix.
        Parameters:
        prefix - the string to look for
        Returns:
        true when the specified string is a prefix of this String, false otherwise
        Throws:
        NullPointerException - when prefix is null
      • startsWith

        public boolean startsWith​(String prefix,
                                  int start)
        Compares the specified string to this String, starting at the specified offset, to determine if the specified string is a prefix.
        Parameters:
        prefix - the string to look for
        start - the starting offset
        Returns:
        true when the specified string occurs in this String at the specified offset, false otherwise
        Throws:
        NullPointerException - when prefix is null
      • strip

        public String strip()
        Strip leading and trailing white space from a string.
        Returns:
        a substring of the original containing no leading or trailing white space
        Since:
        11
      • stripLeading

        public String stripLeading()
        Strip leading white space from a string.
        Returns:
        a substring of the original containing no leading white space
        Since:
        11
      • stripTrailing

        public String stripTrailing()
        Strip trailing white space from a string.
        Returns:
        a substring of the original containing no trailing white space
        Since:
        11
      • isBlank

        public boolean isBlank()
        Determine if the string contains only white space characters.
        Returns:
        true if the string is empty or contains only white space characters, otherwise false.
        Since:
        11
      • lines

        public Stream<String> lines()
        Returns a stream of substrings extracted from this string partitioned by line terminators. Line terminators recognized are line feed "\n", carriage return "\r", and carriage return followed by line feed "\r\n".
        Returns:
        the stream of this string's substrings partitioned by line terminators
        Since:
        11
      • substring

        public String substring​(int start)
        Copies a range of characters into a new String.
        Parameters:
        start - the offset of the first character
        Returns:
        a new String containing the characters from start to the end of the string
        Throws:
        IndexOutOfBoundsException - when start < 0 or start > length()
      • substring

        public String substring​(int start,
                                int end)
        Copies a range of characters.
        Parameters:
        start - the offset of the first character
        end - the offset one past the last character
        Returns:
        a String containing the characters from start to end - 1
        Throws:
        IndexOutOfBoundsException - when start < 0, start > end or end > length()
      • toCharArray

        public char[] toCharArray()
        Copies the characters in this String to a character array.
        Returns:
        a character array containing the characters of this String
      • toLowerCase

        public String toLowerCase()
        Converts the characters in this String to lowercase, using the default Locale. To convert to lower case independent of any locale, use toLowerCase(Locale.ROOT).
        Returns:
        a new String containing the lowercase characters equivalent to the characters in this String
      • toLowerCase

        public String toLowerCase​(Locale locale)
        Converts the characters in this String to lowercase, using the specified Locale.
        Parameters:
        locale - the Locale
        Returns:
        a String containing the lowercase characters equivalent to the characters in this String
      • toString

        public String toString()
        Answers a string containing a concise, human-readable description of the receiver.
        Specified by:
        toString in interface CharSequence
        Overrides:
        toString in class Object
        Returns:
        this String
      • toUpperCase

        public String toUpperCase()
        Converts the characters in this String to uppercase, using the default Locale. To convert to upper case independent of any locale, use toUpperCase(Locale.ROOT).
        Returns:
        a String containing the uppercase characters equivalent to the characters in this String
      • toUpperCase

        public String toUpperCase​(Locale locale)
        Converts the characters in this String to uppercase, using the specified Locale.
        Parameters:
        locale - the Locale
        Returns:
        a String containing the uppercase characters equivalent to the characters in this String
      • trim

        public String trim()
        Removes white space characters from the beginning and end of the string.
        Returns:
        a String with characters <= \\u0020 removed from the beginning and the end
      • valueOf

        public static String valueOf​(char[] data)
        Returns a String containing the characters in the specified character array. Modifying the character array after creating the String has no effect on the String.
        Parameters:
        data - the array of characters
        Returns:
        the String
        Throws:
        NullPointerException - when data is null
      • valueOf

        public static String valueOf​(char[] data,
                                     int start,
                                     int length)
        Returns a String containing the specified characters in the character array. Modifying the character array after creating the String has no effect on the String.
        Parameters:
        data - the array of characters
        start - the starting offset in the character array
        length - the number of characters to use
        Returns:
        the String
        Throws:
        IndexOutOfBoundsException - when length < 0, start < 0 or start + length > data.length
        NullPointerException - when data is null
      • valueOf

        public static String valueOf​(char value)
        Converts the specified character to its string representation.
        Parameters:
        value - the character
        Returns:
        the character converted to a string
      • valueOf

        public static String valueOf​(double value)
        Converts the specified double to its string representation.
        Parameters:
        value - the double
        Returns:
        the double converted to a string
      • valueOf

        public static String valueOf​(float value)
        Converts the specified float to its string representation.
        Parameters:
        value - the float
        Returns:
        the float converted to a string
      • valueOf

        public static String valueOf​(int value)
        Converts the specified integer to its string representation.
        Parameters:
        value - the integer
        Returns:
        the integer converted to a string
      • valueOf

        public static String valueOf​(long value)
        Converts the specified long to its string representation.
        Parameters:
        value - the long
        Returns:
        the long converted to a string
      • valueOf

        public static String valueOf​(Object value)
        Converts the specified object to its string representation. If the object is null answer the string "null", otherwise use toString() to get the string representation.
        Parameters:
        value - the object
        Returns:
        the object converted to a string
      • valueOf

        public static String valueOf​(boolean value)
        Converts the specified boolean to its string representation. When the boolean is true answer "true", otherwise answer "false".
        Parameters:
        value - the boolean
        Returns:
        the boolean converted to a string
      • contentEquals

        public boolean contentEquals​(StringBuffer buffer)
        Answers whether the characters in the StringBuffer buffer are the same as those in this String.
        Parameters:
        buffer - the StringBuffer to compare this String to
        Returns:
        true when the characters in buffer are identical to those in this String. If they are not, false will be returned.
        Throws:
        NullPointerException - when buffer is null
        Since:
        1.4
      • matches

        public boolean matches​(String expr)
        Determines whether a this String matches a given regular expression.
        Parameters:
        expr - the regular expression to be matched
        Returns:
        true if the expression matches, otherwise false
        Throws:
        PatternSyntaxException - if the syntax of the supplied regular expression is not valid
        NullPointerException - if expr is null
        Since:
        1.4
      • replaceAll

        public String replaceAll​(String regex,
                                 String substitute)
        Replace any substrings within this String that match the supplied regular expression expr, with the String substitute.
        Parameters:
        regex - the regular expression to match
        substitute - the string to replace the matching substring with
        Returns:
        the new string
        Throws:
        NullPointerException - if expr is null
        Since:
        1.4
      • replaceFirst

        public String replaceFirst​(String expr,
                                   String substitute)
        Replace any substrings within this String that match the supplied regular expression expr, with the String substitute.
        Parameters:
        expr - the regular expression to match
        substitute - the string to replace the matching substring with
        Returns:
        the new string
        Throws:
        NullPointerException - if expr is null
        Since:
        1.4
      • split

        public String[] split​(String regex)
        Splits this string around matches of the given regular expression. Calling this method is same as calling split(regex,0). Therefore, empty string(s) at the end of the returned array will be discarded.
        Parameters:
        regex - Regular expression that is used as a delimiter
        Returns:
        The array of strings which are split around the regex
        Throws:
        PatternSyntaxException - if the syntax of regex is invalid
        Since:
        1.4
      • split

        public String[] split​(String regex,
                              int max)
        Splits this String using the given regular expression. max controls the number of times the regex is applied to this string. If max is positive, then regex can be applied to this String max-1 times. The returned array size can not be bigger than max, and the last element of the returned array contains all input after the last match of the regex. If max is negative or zero, then regex can be applied to this string as many times as possible and there is no size limit in the returned array. If max is 0, all the empty string(s) at the end of the returned array will be discarded.
        Parameters:
        regex - Regular expression that is used as a delimiter
        max - The threshold of the returned array
        Returns:
        The array of strings which are split around the regex
        Throws:
        PatternSyntaxException - if the syntax of regex is invalid
        Since:
        1.4
      • subSequence

        public CharSequence subSequence​(int start,
                                        int end)
        Has the same result as the substring function, but is present so that String may implement the CharSequence interface.
        Specified by:
        subSequence in interface CharSequence
        Parameters:
        start - the offset the first character
        end - the offset of one past the last character to include
        Returns:
        the subsequence requested
        Throws:
        IndexOutOfBoundsException - when start or end is less than zero, start is greater than end, or end is greater than the length of the String.
        Since:
        1.4
        See Also:
        CharSequence.subSequence(int, int)
      • codePointAt

        public int codePointAt​(int index)
        Returns the Unicode character at the given point.
        Parameters:
        index - the character index
        Returns:
        the Unicode character value at the index
        Since:
        1.5
      • codePointBefore

        public int codePointBefore​(int index)
        Returns the Unicode character before the given point.
        Parameters:
        index - the character index
        Returns:
        the Unicode character value before the index
        Since:
        1.5
      • codePointCount

        public int codePointCount​(int start,
                                  int end)
        Returns the total Unicode values in the specified range.
        Parameters:
        start - first index
        end - last index
        Returns:
        the total Unicode values
        Since:
        1.5
      • offsetByCodePoints

        public int offsetByCodePoints​(int start,
                                      int codePointCount)
        Returns the index of the code point that was offset by codePointCount.
        Parameters:
        start - the position to offset
        codePointCount - the code point count
        Returns:
        the offset index
        Since:
        1.5
      • contentEquals

        public boolean contentEquals​(CharSequence sequence)
        Compares the content of the character sequence to this String
        Parameters:
        sequence - the character sequence
        Returns:
        true if the content of this String is equal to the character sequence, false otherwise.
        Since:
        1.5
      • contains

        public boolean contains​(CharSequence sequence)
        Parameters:
        sequence - the sequence to compare to
        Returns:
        true if this String contains the sequence, false otherwise.
        Since:
        1.5
      • replace

        public String replace​(CharSequence sequence1,
                              CharSequence sequence2)
        Parameters:
        sequence1 - the old character sequence
        sequence2 - the new character sequence
        Returns:
        the new String
        Since:
        1.5
      • format

        public static String format​(String format,
                                    Object... args)
        Format the receiver using the specified format and args.
        Parameters:
        format - the format to use
        args - the format arguments to use
        Returns:
        the formatted result
        See Also:
        Formatter.format(String, Object...)
      • format

        public static String format​(Locale locale,
                                    String format,
                                    Object... args)
        Format the receiver using the specified local, format and args.
        Parameters:
        locale - the locale used to create the Formatter, may be null
        format - the format to use
        args - the format arguments to use
        Returns:
        the formatted result
        See Also:
        Formatter.format(String, Object...)
      • isEmpty

        public boolean isEmpty()
        Answers if this String has no characters, a length of zero.
        Returns:
        true if this String has no characters, false otherwise
        Since:
        1.6
        See Also:
        length()
      • getBytes

        public byte[] getBytes​(Charset charset)
        Converts this String to a byte encoding using the specified Charset.
        Parameters:
        charset - the Charset to use
        Returns:
        the byte array encoding of this String
        Since:
        1.6
      • join

        public static String join​(CharSequence delimiter,
                                  CharSequence... elements)
        Creates a new String by putting each element together joined by the delimiter. If an element is null, then "null" is used as string to join.
        Parameters:
        delimiter - Used as joiner to put elements together
        elements - Elements to be joined
        Returns:
        string of joined elements by delimiter
        Throws:
        NullPointerException - if one of the arguments is null
      • join

        public static String join​(CharSequence delimiter,
                                  Iterable<? extends CharSequence> elements)
        Creates a new String by putting each element together joined by the delimiter. If an element is null, then "null" is used as string to join.
        Parameters:
        delimiter - Used as joiner to put elements together
        elements - Elements to be joined
        Returns:
        string of joined elements by delimiter
        Throws:
        NullPointerException - if one of the arguments is null
      • repeat

        public String repeat​(int count)
        Returns a string whose value is the concatenation of this string repeated count times.
        Parameters:
        count - a positive integer indicating the number of times to be repeated
        Returns:
        a string whose value is the concatenation of this string repeated count times
        Throws:
        IllegalArgumentException - if the count is negative
        Since:
        11