我有以下代码
public static void main(String args[]) throws Exception
{
String mySite = "StackOverflow";
System.out.println(mySite.substring(0, 4));
}
这个打印是什么Stac
根据我的理解索引从 0 开始。
S<-0
t<-1
a<-2
c<-3
k<-4
当我指定我需要从索引 0 到索引 4 的字符串时,我希望Stack
返回但它返回Stac
。
当我查看substring(int beginIndex, int endIndex)源代码时,它显示以下内容。
* @param beginIndex the beginning index, inclusive.
* @param endIndex the ending index, exclusive.
有人可以解释在这种情况下包容和排斥是什么意思吗?为什么它没有变得更直观?有谁知道这种行为的任何具体原因?