![](/img/trans.png)
[英]What is the meaning of the spin in the getAndIncrement method in the AtomicInteger class?
[英]what is the meaning of arguments in substring method of String class
class Test {
public static void main(String[] args) {
String str="Hello world";
System.out.println(str.substring(0, 4));
}
}
为什么输出不是 Hello ? 如果子字符串方法的参数分别指示起点和终点。 这里从 0 索引开始,为什么它在索引 4 之前结束。我的意思是为什么这里没有打印索引 4 字符
str.substring(0, 4)
从索引0
包括索引0
到索引4
不包括检索给定str
一部分。 结果是Hell
。
String
类的 Java 文档: public CharSequence subSequence(int beginIndex, int endIndex)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.