String
来源:互联网 发布:淘宝海外 编辑:程序博客网 时间:2024/06/05 07:31
一、String 的substring用法:
我们一般使用 String str = “1231sgdh”;
str = str.substring(3);
正解: str = new String(str.substring(2));
看看源码
/**
* Returns a string that is a substring of this string. The
* substring begins at the specified {@code beginIndex} and
* extends to the character at index {@code endIndex - 1}.
* Thus the length of the substring is {@code endIndex-beginIndex}.
* <p>
* Examples:
* <blockquote><pre>
* "hamburger".substring(4, 8) returns "urge"
* "smiles".substring(1, 5) returns "mile"
* </pre></blockquote>
*
* @param beginIndex the beginning index, inclusive.
* @param endIndex the ending index, exclusive.
* @return the specified substring.
* @exception IndexOutOfBoundsException if the
* {@code beginIndex} is negative, or
* {@code endIndex} is larger than the length of
* this {@code String} object, or
* {@code beginIndex} is larger than
* {@code endIndex}.
*/
public String substring(int beginIndex, int endIndex) {
if (beginIndex < 0) {
throw new StringIndexOutOfBoundsException(beginIndex);
}
if (endIndex > value.length) {
}
int subLen = endIndex - beginIndex;
if (subLen < 0) {
throw new StringIndexOutOfBoundsException(subLen);
}
return ((beginIndex == 0) && (endIndex == value.length)) ? this
: new String(value, beginIndex, subLen);
}
- string
- String
- String
- string
- string
- String
- string
- String
- string
- string
- string
- string
- String
- String
- string
- string +
- String
- String
- JS
- 关于‘Starting Tomcat v7.0 Server at localhost’ has encountered a problem问题
- 题解:Queue Reconstruction by Height
- BeanFactory和ApplicationContext容器的bean后置处理器方式的不同
- 设计模式三之备忘录模式
- String
- 用grunt搭建自动化的web前端开发环境实战教程(详细步骤)
- spring配置文件报错
- 今天做到一道面试题:JVM的工作原理
- [Hive]那些年踩过的Hive坑
- ios 蓝牙开发,蓝牙应用
- 在二叉查找树中插入节点
- bootstrapValidator通过js手动指定错误提示位置
- java语法基础小结