/** * Copies the specified characters in this string to the character array * starting at the specified offset in the character array. * * @param start * the starting offset of characters to copy. * @param end * the ending offset of characters to copy. * @param buffer * the destination character array. * @param index * the starting offset in the character array. * @throws NullPointerException * if {@code buffer} is {@code null}. * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code end > length()}, {@code start > * end}, {@code index < 0}, {@code end - start > buffer.length - * index} */ public void getChars(int start, int end, char[] buffer, int index) { // Note: last character not copied! if (start >= 0 && start <= end && end <= count) { System.arraycopy(value, start + offset, buffer, index, end - start); } else { // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE. throw startEndAndLength(start, end); } }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
throw startEndAndLength(start, end);
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Copies the specified characters in this string to the character array * starting at the specified offset in the character array. * * @param start * the starting offset of characters to copy. * @param end * the ending offset of characters to copy. * @param buffer * the destination character array. * @param index * the starting offset in the character array. * @throws NullPointerException * if {@code buffer} is {@code null}. * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code end > length()}, {@code start > * end}, {@code index < 0}, {@code end - start > buffer.length - * index} */ public void getChars(int start, int end, char[] buffer, int index) { // Note: last character not copied! if (start >= 0 && start <= end && end <= count) { System.arraycopy(value, start + offset, buffer, index, end - start); } else { // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE. throw startEndAndLength(start, end); } }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Copies the specified characters in this string to the character array * starting at the specified offset in the character array. * * @param start * the starting offset of characters to copy. * @param end * the ending offset of characters to copy. * @param buffer * the destination character array. * @param index * the starting offset in the character array. * @throws NullPointerException * if {@code buffer} is {@code null}. * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code end > length()}, {@code start > * end}, {@code index < 0}, {@code end - start > buffer.length - * index} */ public void getChars(int start, int end, char[] buffer, int index) { // Note: last character not copied! if (start >= 0 && start <= end && end <= count) { System.arraycopy(value, start + offset, buffer, index, end - start); } else { // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE. throw startEndAndLength(start, end); } }
/** * Copies the specified characters in this string to the character array * starting at the specified offset in the character array. * * @param start * the starting offset of characters to copy. * @param end * the ending offset of characters to copy. * @param buffer * the destination character array. * @param index * the starting offset in the character array. * @throws NullPointerException * if {@code buffer} is {@code null}. * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code end > length()}, {@code start > * end}, {@code index < 0}, {@code end - start > buffer.length - * index} */ public void getChars(int start, int end, char[] buffer, int index) { // Note: last character not copied! if (start >= 0 && start <= end && end <= count) { System.arraycopy(value, start + offset, buffer, index, end - start); } else { // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE. throw startEndAndLength(start, end); } }
/** * Returns a string containing a subsequence of characters from this string. * The returned string shares this string's <a href="#backing_array">backing * array</a>. * * @param start * the offset of the first character. * @param end * the offset one past the last character. * @return a new string containing the characters from start to end - 1 * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code start > end} or {@code end > * length()}. */ public String substring(int start, int end) { if (start == 0 && end == count) { return this; } // NOTE last character not copied! // Fast range check. if (start >= 0 && start <= end && end <= count) { return new String(offset + start, end - start, value); } throw startEndAndLength(start, end); }
/** * Copies the specified characters in this string to the character array * starting at the specified offset in the character array. * * @param start * the starting offset of characters to copy. * @param end * the ending offset of characters to copy. * @param buffer * the destination character array. * @param index * the starting offset in the character array. * @throws NullPointerException * if {@code buffer} is {@code null}. * @throws IndexOutOfBoundsException * if {@code start < 0}, {@code end > length()}, {@code start > * end}, {@code index < 0}, {@code end - start > buffer.length - * index} */ public void getChars(int start, int end, char[] buffer, int index) { // Note: last character not copied! if (start >= 0 && start <= end && end <= count) { System.arraycopy(value, start + offset, buffer, index, end - start); } else { // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE. throw startEndAndLength(start, end); } }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }
/** * Calculates the number of Unicode code points between {@code start} * and {@code end}. * * @param start * the inclusive beginning index of the subsequence. * @param end * the exclusive end index of the subsequence. * @return the number of Unicode code points in the subsequence. * @throws IndexOutOfBoundsException * if {@code start < 0 || end > length() || start > end} * @see Character#codePointCount(CharSequence, int, int) * @since 1.5 */ public int codePointCount(int start, int end) { if (start < 0 || end > count || start > end) { throw startEndAndLength(start, end); } return Character.codePointCount(value, offset + start, end - start); }