substring(参数)是java截取字符串的⼀个⽅法。它有两种传参的⽅式:
第⼀种:public String substring(int beginIndex)
返回⼀个新的字符串,它是此字符串的⼀个⼦字符串,该字符串从指定索引出的字符开始,到此字符串末尾结束。第⼆种:public String substring(int beginIndex,int endIndex)
同样返回⼀个新的字符串,该字符串从指定的beginIndex索引处开始,到指定的endIndex索引值结束。不包括endIndex索引处的字符。
所以,该字符串的长度就是endIndex-beginIndex。⽰例⼀:
public class Main {
public static void main(String args[]) { String str = \"this is Java\"; String result = str.substring(8); System.out.println(result); }}
结果: Java⽰例⼆:
public class Main {
public static void main(String args[]) { String str = \"this is Java\";
String result = str.substring(5,10); System.out.println(result); }}
结果:is Ja
以上所述是⼩编给⼤家介绍的java substring 截取字符串的⽅法详解整合,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- dfix.cn 版权所有 湘ICP备2024080961号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务