Class StringBuilder

  • All Implemented Interfaces:
    java.lang.Appendable, java.lang.CharSequence

    public class StringBuilder
    extends java.lang.Object
    implements java.lang.Appendable, java.lang.CharSequence
    A StringBuilder that implements equals and hashcode.
    See Also:
    CharSequence, Appendable, StringBuilder, String
    • Field Summary

      Fields 
      Modifier and Type Field Description
      char[] chars  
      int length  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringBuilder()
      Constructs an instance with an initial capacity of 16.
      StringBuilder​(int capacity)
      Constructs an instance with the specified capacity.
      StringBuilder​(StringBuilder builder)  
      StringBuilder​(java.lang.CharSequence seq)
      Constructs an instance that's initialized with the contents of the specified CharSequence.
      StringBuilder​(java.lang.String string)
      Constructs an instance that's initialized with the contents of the specified String.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      StringBuilder append​(boolean b)
      Appends the string representation of the specified boolean value.
      StringBuilder append​(char c)
      Appends the string representation of the specified char value.
      StringBuilder append​(char[] ch)
      Appends the string representation of the specified char[].
      StringBuilder append​(char[] str, int offset, int len)
      Appends the string representation of the specified subset of the char[].
      StringBuilder append​(double d)
      Appends the string representation of the specified double value.
      StringBuilder append​(float f)
      Appends the string representation of the specified float value.
      StringBuilder append​(int value)
      Appends the string representation of the specified int value.
      StringBuilder append​(int value, int minLength)
      Appends the string representation of the specified int value.
      StringBuilder append​(int value, int minLength, char prefix)
      Appends the string representation of the specified int value.
      StringBuilder append​(long value)
      Appends the string representation of the specified long value.
      StringBuilder append​(long value, int minLength)
      Appends the string representation of the specified long value.
      StringBuilder append​(long value, int minLength, char prefix)
      Appends the string representation of the specified long value.
      StringBuilder append​(StringBuilder builder)  
      StringBuilder append​(StringBuilder builder, int start, int end)  
      StringBuilder append​(java.lang.CharSequence csq)
      Appends the string representation of the specified CharSequence.
      StringBuilder append​(java.lang.CharSequence csq, int start, int end)
      Appends the string representation of the specified subsequence of the CharSequence.
      StringBuilder append​(java.lang.Object obj)
      Appends the string representation of the specified Object.
      StringBuilder append​(java.lang.String str)
      Appends the contents of the specified string.
      StringBuilder append​(java.lang.String str, java.lang.String separator)
      Appends the specified separator if the builder is not empty, then the specified string.
      StringBuilder appendCodePoint​(int codePoint)
      Appends the encoded Unicode code point.
      StringBuilder appendLine​(java.lang.String str)
      Appends the contents of the specified string, then create a new line.
      int capacity()
      Returns the number of characters that can be held without growing.
      char charAt​(int index)
      Retrieves the character at the index.
      void clear()
      Sets length to 0.
      int codePointAt​(int index)
      Retrieves the Unicode code point value at the index.
      int codePointBefore​(int index)
      Retrieves the Unicode code point value that precedes the index.
      int codePointCount​(int beginIndex, int endIndex)
      Calculates the number of Unicode code points between beginIndex and endIndex.
      boolean contains​(java.lang.String subString)  
      boolean containsIgnoreCase​(java.lang.String subString)  
      StringBuilder delete​(int start, int end)
      Deletes a sequence of characters specified by start and end.
      StringBuilder deleteCharAt​(int index)
      Deletes the character at the specified index.
      void ensureCapacity​(int min)
      Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged.
      boolean equals​(java.lang.Object obj)  
      boolean equalsIgnoreCase​(StringBuilder other)  
      boolean equalsIgnoreCase​(java.lang.String other)  
      void getChars​(int start, int end, char[] dest, int destStart)
      Copies the requested sequence of characters to the char[] passed starting at destStart.
      int hashCode()  
      int indexOf​(java.lang.String string)
      Searches for the first index of the specified character.
      int indexOf​(java.lang.String subString, int start)
      Searches for the index of the specified character.
      int indexOfIgnoreCase​(java.lang.String subString, int start)  
      StringBuilder insert​(int offset, boolean b)
      Inserts the string representation of the specified boolean value at the specified offset.
      StringBuilder insert​(int offset, char c)
      Inserts the string representation of the specified char value at the specified offset.
      StringBuilder insert​(int offset, char[] ch)
      Inserts the string representation of the specified char[] at the specified offset.
      StringBuilder insert​(int offset, char[] str, int strOffset, int strLen)
      Inserts the string representation of the specified subsequence of the char[] at the specified offset.
      StringBuilder insert​(int offset, double d)
      Inserts the string representation of the specified double value at the specified offset.
      StringBuilder insert​(int offset, float f)
      Inserts the string representation of the specified float value at the specified offset.
      StringBuilder insert​(int offset, int i)
      Inserts the string representation of the specified int value at the specified offset.
      StringBuilder insert​(int offset, long l)
      Inserts the string representation of the specified long value at the specified offset.
      StringBuilder insert​(int offset, java.lang.CharSequence s)
      Inserts the string representation of the specified CharSequence at the specified offset.
      StringBuilder insert​(int offset, java.lang.CharSequence s, int start, int end)
      Inserts the string representation of the specified subsequence of the CharSequence at the specified offset.
      StringBuilder insert​(int offset, java.lang.Object obj)
      Inserts the string representation of the specified Object at the specified offset.
      StringBuilder insert​(int offset, java.lang.String str)
      Inserts the specified string at the specified offset.
      boolean isEmpty()  
      int lastIndexOf​(java.lang.String string)
      Searches for the last index of the specified character.
      int lastIndexOf​(java.lang.String subString, int start)
      Searches for the index of the specified character.
      int length()
      The current length.
      boolean notEmpty()  
      static int numChars​(int value, int radix)  
      static int numChars​(long value, int radix)  
      int offsetByCodePoints​(int index, int codePointOffset)
      Returns the index that is offset codePointOffset code points from index.
      StringBuilder replace​(char find, java.lang.String replace)
      Replaces all instances of find with replace.
      StringBuilder replace​(int start, int end, java.lang.String str)
      Replaces the specified subsequence in this builder with the specified string.
      StringBuilder replace​(java.lang.String find, java.lang.String replace)
      Replaces all instances of find with replace.
      StringBuilder reverse()
      Reverses the order of characters in this builder.
      void setCharAt​(int index, char ch)
      Sets the character at the index.
      void setLength​(int newLength)
      Sets the current length to a new value.
      java.lang.CharSequence subSequence​(int start, int end)
      Returns a CharSequence of the subsequence from the start index to the end index.
      java.lang.String substring​(int start)
      Returns the String value of the subsequence from the start index to the current end.
      java.lang.String substring​(int start, int end)
      Returns the String value of the subsequence from the start index to the end index.
      java.lang.String toString()
      Returns the current String representation.
      java.lang.String toStringAndClear()
      Returns the current String representation and clears the StringBuilder.
      void trimToSize()
      Trims off any extra capacity beyond the current length.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.CharSequence

        chars, codePoints
    • Field Detail

      • chars

        public char[] chars
      • length

        public int length
    • Constructor Detail

      • StringBuilder

        public StringBuilder()
        Constructs an instance with an initial capacity of 16.
        See Also:
        capacity()
      • StringBuilder

        public StringBuilder​(int capacity)
        Constructs an instance with the specified capacity.
        Parameters:
        capacity - the initial capacity to use.
        Throws:
        java.lang.NegativeArraySizeException - if the specified capacity is negative.
        See Also:
        capacity()
      • StringBuilder

        public StringBuilder​(java.lang.CharSequence seq)
        Constructs an instance that's initialized with the contents of the specified CharSequence. The capacity of the new builder will be the length of the CharSequence plus 16.
        Parameters:
        seq - the CharSequence to copy into the builder.
        Throws:
        java.lang.NullPointerException - if seq is null.
      • StringBuilder

        public StringBuilder​(java.lang.String string)
        Constructs an instance that's initialized with the contents of the specified String. The capacity of the new builder will be the length of the String plus 16.
        Parameters:
        string - the String to copy into the builder.
        Throws:
        java.lang.NullPointerException - if str is null.
    • Method Detail

      • numChars

        public static int numChars​(int value,
                                   int radix)
        Returns:
        the number of characters required to represent the specified value with the specified radix
      • numChars

        public static int numChars​(long value,
                                   int radix)
        Returns:
        the number of characters required to represent the specified value with the specified radix
      • capacity

        public int capacity()
        Returns the number of characters that can be held without growing.
        Returns:
        the capacity
        See Also:
        ensureCapacity(int), length
      • charAt

        public char charAt​(int index)
        Retrieves the character at the index.
        Specified by:
        charAt in interface java.lang.CharSequence
        Parameters:
        index - the index of the character to retrieve.
        Returns:
        the char value.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative or greater than or equal to the current length().
      • ensureCapacity

        public void ensureCapacity​(int min)
        Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. The general policy of this method is that if the minimumCapacity is larger than the current capacity(), then the capacity will be increased to the largest value of either the minimumCapacity or the current capacity multiplied by two plus two. Although this is the general policy, there is no guarantee that the capacity will change.
        Parameters:
        min - the new minimum capacity to set.
      • getChars

        public void getChars​(int start,
                             int end,
                             char[] dest,
                             int destStart)
        Copies the requested sequence of characters to the char[] passed starting at destStart.
        Parameters:
        start - the inclusive start index of the characters to copy.
        end - the exclusive end index of the characters to copy.
        dest - the char[] to copy the characters to.
        destStart - the inclusive start index of dest to begin copying to.
        Throws:
        java.lang.IndexOutOfBoundsException - if the start is negative, the destStart is negative, the start is greater than end, the end is greater than the current length() or destStart + end - begin is greater than dest.length.
      • length

        public int length()
        The current length.
        Specified by:
        length in interface java.lang.CharSequence
        Returns:
        the number of characters contained in this instance.
      • setCharAt

        public void setCharAt​(int index,
                              char ch)
        Sets the character at the index.
        Parameters:
        index - the zero-based index of the character to replace.
        ch - the character to set.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative or greater than or equal to the current length().
      • setLength

        public void setLength​(int newLength)
        Sets the current length to a new value. If the new length is larger than the current length, then the new characters at the end of this object will contain the char value of .
        Parameters:
        newLength - the new length of this StringBuilder.
        Throws:
        java.lang.IndexOutOfBoundsException - if length < 0.
        See Also:
        length
      • substring

        public java.lang.String substring​(int start)
        Returns the String value of the subsequence from the start index to the current end.
        Parameters:
        start - the inclusive start index to begin the subsequence.
        Returns:
        a String containing the subsequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if start is negative or greater than the current length().
      • substring

        public java.lang.String substring​(int start,
                                          int end)
        Returns the String value of the subsequence from the start index to the end index.
        Parameters:
        start - the inclusive start index to begin the subsequence.
        end - the exclusive end index to end the subsequence.
        Returns:
        a String containing the subsequence.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if start is negative, greater than end or if end is greater than the current length().
      • toString

        public java.lang.String toString()
        Returns the current String representation.
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String containing the characters in this instance.
      • toStringAndClear

        public java.lang.String toStringAndClear()
        Returns the current String representation and clears the StringBuilder.
        Returns:
        a String containing the characters in this instance.
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Returns a CharSequence of the subsequence from the start index to the end index.
        Specified by:
        subSequence in interface java.lang.CharSequence
        Parameters:
        start - the inclusive start index to begin the subsequence.
        end - the exclusive end index to end the subsequence.
        Returns:
        a CharSequence containing the subsequence.
        Throws:
        java.lang.IndexOutOfBoundsException - if start is negative, greater than end or if end is greater than the current length().
        Since:
        1.4
      • indexOf

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

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

        public int indexOfIgnoreCase​(java.lang.String subString,
                                     int start)
      • contains

        public boolean contains​(java.lang.String subString)
      • containsIgnoreCase

        public boolean containsIgnoreCase​(java.lang.String subString)
      • lastIndexOf

        public int lastIndexOf​(java.lang.String string)
        Searches for the last index of the specified character. The search for the character starts at the end and moves towards the beginning.
        Parameters:
        string - the string to find.
        Returns:
        the index of the specified character, -1 if the character isn't found.
        Throws:
        java.lang.NullPointerException - if string is null.
        Since:
        1.4
        See Also:
        String.lastIndexOf(java.lang.String)
      • lastIndexOf

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

        public void trimToSize()
        Trims off any extra capacity beyond the current length. Note, this method is NOT guaranteed to change the capacity of this object.
        Since:
        1.5
      • codePointAt

        public int codePointAt​(int index)
        Retrieves the Unicode code point value at the index.
        Parameters:
        index - the index to the char code unit.
        Returns:
        the Unicode code point value.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative or greater than or equal to length().
        Since:
        1.5
        See Also:
        Character, Character.codePointAt(char[], int, int)
      • codePointBefore

        public int codePointBefore​(int index)
        Retrieves the Unicode code point value that precedes the index.
        Parameters:
        index - the index to the char code unit within this object.
        Returns:
        the Unicode code point value.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is less than 1 or greater than length().
        Since:
        1.5
        See Also:
        Character, Character.codePointBefore(char[], int, int)
      • codePointCount

        public int codePointCount​(int beginIndex,
                                  int endIndex)
        Calculates the number of Unicode code points between beginIndex and endIndex.
        Parameters:
        beginIndex - the inclusive beginning index of the subsequence.
        endIndex - the exclusive end index of the subsequence.
        Returns:
        the number of Unicode code points in the subsequence.
        Throws:
        java.lang.IndexOutOfBoundsException - if beginIndex is negative or greater than endIndex or endIndex is greater than length().
        Since:
        1.5
        See Also:
        Character, Character.codePointCount(char[], int, int)
      • offsetByCodePoints

        public int offsetByCodePoints​(int index,
                                      int codePointOffset)
        Returns the index that is offset codePointOffset code points from index.
        Parameters:
        index - the index to calculate the offset from.
        codePointOffset - the number of code points to count.
        Returns:
        the index that is codePointOffset code points away from index.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative or greater than length() or if there aren't enough code points before or after index to match codePointOffset.
        Since:
        1.5
        See Also:
        Character, Character.offsetByCodePoints(char[], int, int, int, int)
      • append

        public StringBuilder append​(boolean b)
        Appends the string representation of the specified boolean value. The boolean value is converted to a String according to the rule defined by String.valueOf(boolean).
        Parameters:
        b - the boolean value to append.
        Returns:
        this builder.
        See Also:
        String.valueOf(boolean)
      • append

        public StringBuilder append​(char c)
        Appends the string representation of the specified char value. The char value is converted to a string according to the rule defined by String.valueOf(char).
        Specified by:
        append in interface java.lang.Appendable
        Parameters:
        c - the char value to append.
        Returns:
        this builder.
        See Also:
        String.valueOf(char)
      • append

        public StringBuilder append​(int value)
        Appends the string representation of the specified int value. The int value is converted to a string without memory allocation.
        Parameters:
        value - the int value to append.
        Returns:
        this builder.
        See Also:
        String.valueOf(int)
      • append

        public StringBuilder append​(int value,
                                    int minLength)
        Appends the string representation of the specified int value. The int value is converted to a string without memory allocation.
        Parameters:
        value - the int value to append.
        minLength - the minimum number of characters to add
        Returns:
        this builder.
        See Also:
        String.valueOf(int)
      • append

        public StringBuilder append​(int value,
                                    int minLength,
                                    char prefix)
        Appends the string representation of the specified int value. The int value is converted to a string without memory allocation.
        Parameters:
        value - the int value to append.
        minLength - the minimum number of characters to add
        prefix - the character to use as prefix
        Returns:
        this builder.
        See Also:
        String.valueOf(int)
      • append

        public StringBuilder append​(long value)
        Appends the string representation of the specified long value. The long value is converted to a string without memory allocation.
        Parameters:
        value - the long value.
        Returns:
        this builder.
      • append

        public StringBuilder append​(long value,
                                    int minLength)
        Appends the string representation of the specified long value. The long value is converted to a string without memory allocation.
        Parameters:
        value - the long value.
        minLength - the minimum number of characters to add
        Returns:
        this builder.
      • append

        public StringBuilder append​(long value,
                                    int minLength,
                                    char prefix)
        Appends the string representation of the specified long value. The long value is converted to a string without memory allocation.
        Parameters:
        value - the long value.
        minLength - the minimum number of characters to add
        prefix - the character to use as prefix
        Returns:
        this builder.
      • append

        public StringBuilder append​(float f)
        Appends the string representation of the specified float value. The float value is converted to a string according to the rule defined by String.valueOf(float).
        Parameters:
        f - the float value to append.
        Returns:
        this builder.
      • append

        public StringBuilder append​(double d)
        Appends the string representation of the specified double value. The double value is converted to a string according to the rule defined by String.valueOf(double).
        Parameters:
        d - the double value to append.
        Returns:
        this builder.
        See Also:
        String.valueOf(double)
      • append

        public StringBuilder append​(java.lang.Object obj)
        Appends the string representation of the specified Object. The Object value is converted to a string according to the rule defined by String.valueOf(Object).
        Parameters:
        obj - the Object to append.
        Returns:
        this builder.
        See Also:
        String.valueOf(Object)
      • append

        public StringBuilder append​(java.lang.String str)
        Appends the contents of the specified string. If the string is null, then the string "null" is appended.
        Parameters:
        str - the string to append.
        Returns:
        this builder.
      • append

        public StringBuilder append​(java.lang.String str,
                                    java.lang.String separator)
        Appends the specified separator if the builder is not empty, then the specified string.
      • appendLine

        public StringBuilder appendLine​(java.lang.String str)
        Appends the contents of the specified string, then create a new line. If the string is null, then the string "null" is appended.
        Parameters:
        str - the string to append.
        Returns:
        this builder.
      • append

        public StringBuilder append​(char[] ch)
        Appends the string representation of the specified char[]. The char[] is converted to a string according to the rule defined by String.valueOf(char[]).
        Parameters:
        ch - the char[] to append..
        Returns:
        this builder.
        See Also:
        String.valueOf(char[])
      • append

        public StringBuilder append​(char[] str,
                                    int offset,
                                    int len)
        Appends the string representation of the specified subset of the char[]. The char[] value is converted to a String according to the rule defined by String.valueOf(char[],int,int).
        Parameters:
        str - the char[] to append.
        offset - the inclusive offset index.
        len - the number of characters.
        Returns:
        this builder.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if offset and len do not specify a valid subsequence.
        See Also:
        String.valueOf(char[],int,int)
      • append

        public StringBuilder append​(java.lang.CharSequence csq)
        Appends the string representation of the specified CharSequence. If the CharSequence is null, then the string "null" is appended.
        Specified by:
        append in interface java.lang.Appendable
        Parameters:
        csq - the CharSequence to append.
        Returns:
        this builder.
      • append

        public StringBuilder append​(java.lang.CharSequence csq,
                                    int start,
                                    int end)
        Appends the string representation of the specified subsequence of the CharSequence. If the CharSequence is null, then the string "null" is used to extract the subsequence from.
        Specified by:
        append in interface java.lang.Appendable
        Parameters:
        csq - the CharSequence to append.
        start - the beginning index.
        end - the ending index.
        Returns:
        this builder.
        Throws:
        java.lang.IndexOutOfBoundsException - if start or end are negative, start is greater than end or end is greater than the length of csq.
      • appendCodePoint

        public StringBuilder appendCodePoint​(int codePoint)
        Appends the encoded Unicode code point. The code point is converted to a char[] as defined by Character.toChars(int).
        Parameters:
        codePoint - the Unicode code point to encode and append.
        Returns:
        this builder.
        See Also:
        Character.toChars(int)
      • delete

        public StringBuilder delete​(int start,
                                    int end)
        Deletes a sequence of characters specified by start and end. Shifts any remaining characters to the left.
        Parameters:
        start - the inclusive start index.
        end - the exclusive end index.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if start is less than zero, greater than the current length or greater than end.
      • deleteCharAt

        public StringBuilder deleteCharAt​(int index)
        Deletes the character at the specified index. shifts any remaining characters to the left.
        Parameters:
        index - the index of the character to delete.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if index is less than zero or is greater than or equal to the current length.
      • clear

        public void clear()
        Sets length to 0.
      • insert

        public StringBuilder insert​(int offset,
                                    boolean b)
        Inserts the string representation of the specified boolean value at the specified offset. The boolean value is converted to a string according to the rule defined by String.valueOf(boolean).
        Parameters:
        offset - the index to insert at.
        b - the boolean value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length.
        See Also:
        String.valueOf(boolean)
      • insert

        public StringBuilder insert​(int offset,
                                    char c)
        Inserts the string representation of the specified char value at the specified offset. The char value is converted to a string according to the rule defined by String.valueOf(char).
        Parameters:
        offset - the index to insert at.
        c - the char value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.IndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(char)
      • insert

        public StringBuilder insert​(int offset,
                                    int i)
        Inserts the string representation of the specified int value at the specified offset. The int value is converted to a String according to the rule defined by String.valueOf(int).
        Parameters:
        offset - the index to insert at.
        i - the int value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(int)
      • insert

        public StringBuilder insert​(int offset,
                                    long l)
        Inserts the string representation of the specified long value at the specified offset. The long value is converted to a String according to the rule defined by String.valueOf(long).
        Parameters:
        offset - the index to insert at.
        l - the long value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current {code length()}.
        See Also:
        String.valueOf(long)
      • insert

        public StringBuilder insert​(int offset,
                                    float f)
        Inserts the string representation of the specified float value at the specified offset. The float value is converted to a string according to the rule defined by String.valueOf(float).
        Parameters:
        offset - the index to insert at.
        f - the float value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(float)
      • insert

        public StringBuilder insert​(int offset,
                                    double d)
        Inserts the string representation of the specified double value at the specified offset. The double value is converted to a String according to the rule defined by String.valueOf(double).
        Parameters:
        offset - the index to insert at.
        d - the double value to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(double)
      • insert

        public StringBuilder insert​(int offset,
                                    java.lang.Object obj)
        Inserts the string representation of the specified Object at the specified offset. The Object value is converted to a String according to the rule defined by String.valueOf(Object).
        Parameters:
        offset - the index to insert at.
        obj - the Object to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(Object)
      • insert

        public StringBuilder insert​(int offset,
                                    java.lang.String str)
        Inserts the specified string at the specified offset. If the specified string is null, then the String "null" is inserted.
        Parameters:
        offset - the index to insert at.
        str - the String to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
      • insert

        public StringBuilder insert​(int offset,
                                    char[] ch)
        Inserts the string representation of the specified char[] at the specified offset. The char[] value is converted to a String according to the rule defined by String.valueOf(char[]).
        Parameters:
        offset - the index to insert at.
        ch - the char[] to insert.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        String.valueOf(char[])
      • insert

        public StringBuilder insert​(int offset,
                                    char[] str,
                                    int strOffset,
                                    int strLen)
        Inserts the string representation of the specified subsequence of the char[] at the specified offset. The char[] value is converted to a String according to the rule defined by String.valueOf(char[],int,int).
        Parameters:
        offset - the index to insert at.
        str - the char[] to insert.
        strOffset - the inclusive index.
        strLen - the number of characters.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if offset is negative or greater than the current length(), or strOffset and strLen do not specify a valid subsequence.
        See Also:
        String.valueOf(char[],int,int)
      • insert

        public StringBuilder insert​(int offset,
                                    java.lang.CharSequence s)
        Inserts the string representation of the specified CharSequence at the specified offset. The CharSequence is converted to a String as defined by CharSequence.toString(). If s is null, then the String "null" is inserted.
        Parameters:
        offset - the index to insert at.
        s - the CharSequence to insert.
        Returns:
        this builder.
        Throws:
        java.lang.IndexOutOfBoundsException - if offset is negative or greater than the current length().
        See Also:
        CharSequence.toString()
      • insert

        public StringBuilder insert​(int offset,
                                    java.lang.CharSequence s,
                                    int start,
                                    int end)
        Inserts the string representation of the specified subsequence of the CharSequence at the specified offset. The CharSequence is converted to a String as defined by CharSequence.subSequence(int, int). If the CharSequence is null, then the string "null" is used to determine the subsequence.
        Parameters:
        offset - the index to insert at.
        s - the CharSequence to insert.
        start - the start of the subsequence of the character sequence.
        end - the end of the subsequence of the character sequence.
        Returns:
        this builder.
        Throws:
        java.lang.IndexOutOfBoundsException - if offset is negative or greater than the current length(), or start and end do not specify a valid subsequence.
        See Also:
        CharSequence.subSequence(int, int)
      • replace

        public StringBuilder replace​(int start,
                                     int end,
                                     java.lang.String str)
        Replaces the specified subsequence in this builder with the specified string.
        Parameters:
        start - the inclusive begin index.
        end - the exclusive end index.
        str - the replacement string.
        Returns:
        this builder.
        Throws:
        java.lang.StringIndexOutOfBoundsException - if start is negative, greater than the current length() or greater than end.
        java.lang.NullPointerException - if str is null.
      • replace

        public StringBuilder replace​(java.lang.String find,
                                     java.lang.String replace)
        Replaces all instances of find with replace.
      • replace

        public StringBuilder replace​(char find,
                                     java.lang.String replace)
        Replaces all instances of find with replace.
      • reverse

        public StringBuilder reverse()
        Reverses the order of characters in this builder.
        Returns:
        this buffer.
      • isEmpty

        public boolean isEmpty()
      • notEmpty

        public boolean notEmpty()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(@Null
                                        java.lang.String other)