实施String#charAt(int index)了Oracle的Java 7:
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}
Run Code Online (Sandbox Code Playgroud)
检查有点安全,但这是完全相同的行为.
返回它实际上会更慢 char[]
public char[] toCharArray() {
// Cannot use Arrays.copyOf because of class initialization order issues
char result[] = new char[value.length];
System.arraycopy(value, 0, result, 0, value.length);
return result;
}
Run Code Online (Sandbox Code Playgroud)
因为你必须先复制它.
| 归档时间: |
|
| 查看次数: |
4229 次 |
| 最近记录: |