java.lang.StringBuilder.substring(int start, int end)方法实例
width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="box-sizing: border-box; left: 0px; position: absolute; top: 0px;">
id="iframeu1064372_0" src="http://pos.baidu.com/lcqm?rdid=1064372&dc=2&di=u1064372&dri=0&dis=0&dai=1&ps=377x386&dcb=BAIDU_SSP_define&dtm=BAIDU_DUP_SETJSONADSLOT&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1464853188789&ti=java.lang.StringBuilder.substring(int%20start%2C%20int%20end)%E6%96%B9%E6%B3%95%E5%AE%9E%E4%BE%8B%20-%20&ari=1&dbv=2&drs=1&pcs=1423x772&pss=1423x1661&cfv=0&cpl=26&chi=1&cce=true&cec=UTF-8&tlm=1464853188<u=http%3A%2F%2Fwww.yiibai.com%2Fjava%2Flang%2Fstringbuilder_substring_end.html<r=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DWVYlplvpUZ-0MyKERYf3KGsw0ckPw09ToL_S159EsbpEOqivy_l9PDN5hhklK1xfwMJ2Jfzc1rDggUzDweTIKrgGkeycCRy_SiVLV4zblW3%26wd%3D%26eqid%3Db6d82982000126f900000005574fe298&ecd=1&psr=1440x900&par=1440x870&pis=-1x-1&ccd=24&cja=false&cmi=43&col=zh-CN&cdo=-1&tcn=1464853189&qn=bd44d937a1b4fd1e&tt=1464853188712.103.454.462" width="728" height="90" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="box-sizing: border-box; border-width: 0px; border-style: initial; vertical-align: bottom; margin: 0px;">
Windows10用户联盟QQ群: 227270512
java.lang.StringBuilder.substring(int start, int end) 方法返回一个新的String,它包含的字符目前包含在此序列的子序列。该子字符串始于指定的索引start并延伸到字符索引end - 1。
声明
以下是java.lang.StringBuilder.substring()方法的声明
public String substring(int start, int end)
参数
-
start -- 这是开始索引(包括)。
-
end -- 这就是end的索引(不包括)。
返回值
此方法返回新的字符串。
异常
-
StringIndexOutOfBoundsException -- 如果start或end为负或大于length(),或start大于end。
例子
下面的例子显示java.lang.StringBuilder.substring()方法的使用。
package com.yiibai; import java.lang.*; public class StringBuilderDemo { public static void main(String[] args) { StringBuilder str = new StringBuilder("admin"); System.out.println("string = " + str); // prints substring from index 3 System.out.println("substring is = " + str.substring(3)); /* prints substring from index 1 to 4 excluding character at 4th index */ System.out.println("substring is = " + str.substring(1, 4)); } }
让我们来编译和运行上面的程序,这将产生以下结果:
string = admin substring is = in substring is = dmi