⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringbuffer.java

📁 已经移植好的java虚拟机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * </pre></blockquote>     *     * @param      srcBegin   start copying at this offset in the string buffer.     * @param      srcEnd     stop copying at this offset in the string buffer.     * @param      dst        the array to copy the data into.     * @param      dstBegin   offset into <code>dst</code>.     * @exception  NullPointerException if <code>dst</code> is      *             <code>null</code>.     * @exception  IndexOutOfBoundsException  if any of the following is true:     *             <ul>     *             <li><code>srcBegin</code> is negative     *             <li><code>dstBegin</code> is negative     *             <li>the <code>srcBegin</code> argument is greater than      *             the <code>srcEnd</code> argument.     *             <li><code>srcEnd</code> is greater than      *             <code>this.length()</code>, the current length of this      *             string buffer.     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than      *             <code>dst.length</code>     *             </ul>     */    public synchronized void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {        if (srcBegin < 0) {            throw new StringIndexOutOfBoundsException(srcBegin);        }        if ((srcEnd < 0) || (srcEnd > count)) {            throw new StringIndexOutOfBoundsException(srcEnd);        }        if (srcBegin > srcEnd) {            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");        }        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);    }    /**     * The character at the specified index of this string buffer is set      * to <code>ch</code>. The string buffer is altered to represent a new      * character sequence that is identical to the old character sequence,      * except that it contains the character <code>ch</code> at position      * <code>index</code>.      * <p>     * The offset argument must be greater than or equal to      * <code>0</code>, and less than the length of this string buffer.      *     * @param      index   the index of the character to modify.     * @param      ch      the new character.     * @exception  IndexOutOfBoundsException  if <code>index</code> is      *             negative or greater than or equal to <code>length()</code>.     * @see        java.lang.StringBuffer#length()     */    public synchronized void setCharAt(int index, char ch) {        if ((index < 0) || (index >= count)) {            throw new StringIndexOutOfBoundsException(index);        }        if (shared) copy();        value[index] = ch;    }    /**     * Appends the string representation of the <code>Object</code>      * argument to this string buffer.      * <p>     * The argument is converted to a string as if by the method      * <code>String.valueOf</code>, and the characters of that      * string are then appended to this string buffer.      *     * @param   obj   an <code>Object</code>.     * @return  a reference to this <code>StringBuffer</code> object.     * @see     java.lang.String#valueOf(java.lang.Object)     * @see     java.lang.StringBuffer#append(java.lang.String)     */    public synchronized StringBuffer append(Object obj) {        return append(String.valueOf(obj));    }    /**     * Appends the string to this string buffer.      * <p>     * The characters of the <code>String</code> argument are appended, in      * order, to the contents of this string buffer, increasing the      * length of this string buffer by the length of the argument.      * If <code>str</code> is <code>null</code>, then the four characters      * <code>"null"</code> are appended to this string buffer.     * <p>     * Let <i>n</i> be the length of the old character sequence, the one      * contained in the string buffer just prior to execution of the      * <code>append</code> method. Then the character at index <i>k</i> in      * the new character sequence is equal to the character at index <i>k</i>      * in the old character sequence, if <i>k</i> is less than <i>n</i>;      * otherwise, it is equal to the character at index <i>k-n</i> in the      * argument <code>str</code>.     *     * @param   str   a string.     * @return  a reference to this <code>StringBuffer</code>.     */      public native synchronized StringBuffer append(String str);/***** *    public synchronized StringBuffer append(String str) { *      if (str == null) { *          str = String.valueOf(str); *      } * *      int len = str.length(); *      int newcount = count + len; *      if (newcount > value.length) *          expandCapacity(newcount); *      str.getChars(0, len, value, count); *      count = newcount; *      return this; *  } *****/    /**     * Appends the string representation of the <code>char</code> array      * argument to this string buffer.      * <p>     * The characters of the array argument are appended, in order, to      * the contents of this string buffer. The length of this string      * buffer increases by the length of the argument.      * <p>     * The overall effect is exactly as if the argument were converted to      * a string by the method {@link String#valueOf(char[])} and the      * characters of that string were then {@link #append(String) appended}      * to this <code>StringBuffer</code> object.     *     * @param   str   the characters to be appended.     * @return  a reference to this <code>StringBuffer</code> object.     */    public synchronized StringBuffer append(char str[]) {        int len = str.length;        int newcount = count + len;        if (newcount > value.length)            expandCapacity(newcount);        System.arraycopy(str, 0, value, count, len);        count = newcount;        return this;    }    /**     * Appends the string representation of a subarray of the      * <code>char</code> array argument to this string buffer.      * <p>     * Characters of the character array <code>str</code>, starting at      * index <code>offset</code>, are appended, in order, to the contents      * of this string buffer. The length of this string buffer increases      * by the value of <code>len</code>.      * <p>     * The overall effect is exactly as if the arguments were converted to      * a string by the method {@link String#valueOf(char[],int,int)} and the     * characters of that string were then {@link #append(String) appended}      * to this <code>StringBuffer</code> object.     *     * @param   str      the characters to be appended.     * @param   offset   the index of the first character to append.     * @param   len      the number of characters to append.     * @return  a reference to this <code>StringBuffer</code> object.     */    public synchronized StringBuffer append(char str[], int offset, int len) {        int newcount = count + len;        if (newcount > value.length)            expandCapacity(newcount);        System.arraycopy(str, offset, value, count, len);        count = newcount;        return this;    }    /**     * Appends the string representation of the <code>boolean</code>      * argument to the string buffer.      * <p>     * The argument is converted to a string as if by the method      * <code>String.valueOf</code>, and the characters of that      * string are then appended to this string buffer.      *     * @param   b   a <code>boolean</code>.     * @return  a reference to this <code>StringBuffer</code>.     * @see     java.lang.String#valueOf(boolean)     * @see     java.lang.StringBuffer#append(java.lang.String)     */    public StringBuffer append(boolean b) {        return append(String.valueOf(b));    }    /**     * Appends the string representation of the <code>char</code>      * argument to this string buffer.      * <p>     * The argument is appended to the contents of this string buffer.      * The length of this string buffer increases by <code>1</code>.      * <p>     * The overall effect is exactly as if the argument were converted to      * a string by the method {@link String#valueOf(char)} and the character      * in that string were then {@link #append(String) appended} to this      * <code>StringBuffer</code> object.     *     * @param   c   a <code>char</code>.     * @return  a reference to this <code>StringBuffer</code> object.     */    public synchronized StringBuffer append(char c) {        int newcount = count + 1;        if (newcount > value.length)            expandCapacity(newcount);        value[count++] = c;        return this;    }    /**     * Appends the string representation of the <code>int</code>      * argument to this string buffer.      * <p>     * The argument is converted to a string as if by the method      * <code>String.valueOf</code>, and the characters of that      * string are then appended to this string buffer.      *     * @param   i   an <code>int</code>.     * @return  a reference to this <code>StringBuffer</code> object.     * @see     java.lang.String#valueOf(int)     * @see     java.lang.StringBuffer#append(java.lang.String)     */    public native StringBuffer append(int i);/******         *  public StringBuffer append(int i) { *      return append(String.valueOf(i)); *  } ****/    /**     * Appends the string representation of the <code>long</code>      * argument to this string buffer.      * <p>     * The argument is converted to a string as if by the method      * <code>String.valueOf</code>, and the characters of that      * string are then appended to this string buffer.      *     * @param   l   a <code>long</code>.     * @return  a reference to this <code>StringBuffer</code> object.     * @see     java.lang.String#valueOf(long)     * @see     java.lang.StringBuffer#append(java.lang.String)     */    public StringBuffer append(long l) {        return append(String.valueOf(l));    }    /**     * Removes the characters in a substring of this <code>StringBuffer</code>.     * The substring begins at the specified <code>start</code> and extends to     * the character at index <code>end - 1</code> or to the end of the     * <code>StringBuffer</code> if no such character exists. If     * <code>start</code> is equal to <code>end</code>, no changes are made.     *     * @param      start  The beginning index, inclusive.     * @param      end    The ending index, exclusive.     * @return     This string buffer.     * @exception  StringIndexOutOfBoundsException  if <code>start</code>     *             is negative, greater than <code>length()</code>, or     *             greater than <code>end</code>.     * @since      1.2     */    public synchronized StringBuffer delete(int start, int end) {        if (start < 0)            throw new StringIndexOutOfBoundsException(start);        if (end > count)            end = count;        if (start > end)            throw new StringIndexOutOfBoundsException();        int len = end - start;        if (len > 0) {            if (shared)                copy();            System.arraycopy(value, start+len, value, start, count-end);            count -= len;        }        return this;    }    /**     * Removes the character at the specified position in this     * <code>StringBuffer</code> (shortening the <code>StringBuffer</code>     * by one character).     *     * @param       index  Index of character to remove     * @return      This string buffer.     * @exception   StringIndexOutOfBoundsException  if the <code>index</code>     *              is negative or greater than or equal to     *              <code>length()</code>.     * @since       1.2     */    public synchronized StringBuffer deleteCharAt(int index) {        if ((index < 0) || (index >= count))            throw new StringIndexOutOfBoundsException();        if (shared)            copy();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -