标签:lips 源代码 image javase div ble x64 window src
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
code:
package jizuiku.t00; public class Demo5 { public static void main(String[] args) { //索引值 012345 String str = "abc01234543210cba"; int beginIndex = 2; int endIndex = 5;//不包括这个索引所对应的字符,为啥?看看源代码,你就知道. System.out.println(str.substring(beginIndex, endIndex)); } }
result:
scoureCode:
public String substring(int beginIndex, int endIndex) { if (beginIndex < 0) { throw new StringIndexOutOfBoundsException(beginIndex); } if (endIndex > value.length) { throw new StringIndexOutOfBoundsException(endIndex); } int subLen = endIndex - beginIndex; if (subLen < 0) { throw new StringIndexOutOfBoundsException(subLen); } return ((beginIndex == 0) && (endIndex == value.length)) ? this : new String(value, beginIndex, subLen); }
Java优秀,值得学习。
学习资源:API手册+Java源码。
JavaSE8基础 String substring 返回字符串中指定索引值区间内的字符
标签:lips 源代码 image javase div ble x64 window src
原文地址:http://www.cnblogs.com/jizuiku/p/7468964.html