共同学习Java源代码--常用工具类--AbstractStringBuilder(二)
来源:互联网 发布:软件毕业成果报告书 编辑:程序博客网 时间:2024/06/02 09:12
if (newLength < 0)
throw new StringIndexOutOfBoundsException(newLength);
ensureCapacityInternal(newLength);
if (count < newLength) {
Arrays.fill(value, count, newLength, '\0');
}
count = newLength;
}
这个方法是设置可变字符串长度的方法。先判断参数,也就是要设置的长度是否小于零,小于零的话抛出异常。然后调用之前的方法扩大底层数组的长度。然后判断如果已有的字符数小于参数,那么就将扩容后的char数组value从count位到参数所在位置都填满\0也就是空字符。
public char charAt(int index) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
return value[index];
}
这个方法比较简单就是返回指定下标的字符。
public int codePointAt(int index) {
if ((index < 0) || (index >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return Character.codePointAtImpl(value, index, count);
}
这个方法是返回指定下标的代码点。
public int codePointBefore(int index) {
int i = index - 1;
if ((i < 0) || (i >= count)) {
throw new StringIndexOutOfBoundsException(index);
}
return Character.codePointBeforeImpl(value, index, 0);
}
这是获取该元素之前那个元素的代码点。
public int codePointCount(int beginIndex, int endIndex) {
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
throw new IndexOutOfBoundsException();
}
return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
}
这是获取指定下标区间内代码点的数量。
public int offsetByCodePoints(int index, int codePointOffset) {
if (index < 0 || index > count) {
throw new IndexOutOfBoundsException();
}
return Character.offsetByCodePointsImpl(value, 0, count,
index, codePointOffset);
}
这个方法是返回从String对象指定索引开始,到另一个指定索引结束的区间内的代码点长度。
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(二)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(一)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(三)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(四)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(五)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(六)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(七)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(八)
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(九)
- 共同学习Java源代码--常用工具类--StringBuffer(二)
- 共同学习Java源代码--常用工具类--StringBuffer(一)
- 共同学习Java源代码--常用工具类--StringBuffer(三)
- 共同学习Java源代码--常用工具类--StringBuffer(四)
- 共同学习Java源代码--数据结构--AbstractCollection抽象类(二)
- 共同学习Java源代码--数据结构--AbstractList抽象类(二)
- 共同学习Java源代码--数据结构--ArrayList类(二)
- 共同学习Java源代码--数据结构--LinkedList类(二)
- 共同学习Java源代码-数据结构-AbstractMap抽象类(二)
- char *s 和 char s[] 的区别小结
- Android--视频播放器
- serv-u 提权
- initNEW1-BASE.bat
- POJ1651 Multiplication Puzzle 区间DP
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(二)
- xcode高效开发必备! mark,待实践
- kettle乱码问题解决记录
- android webview 在小米物理按键不会走获取标题的 函数
- initNEW2-BASE.bat
- R-CNN笔记0:README.md文件
- The C programing language chapter 7 : Input and Output
- 动态规划
- iOS开发------使用自定义.bundle中的资源文件