java substring 截取字符串的方法
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 截取字符串的方法詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
Spring中@Service注解的作用與@Controller和@RestController之間區(qū)別
這篇文章主要介紹了Spring中@Service注解的作用與@Controller和@RestController之間的區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2023-03-03
Spring實戰(zhàn)之抽象Bean和子Bean定義與用法示例
這篇文章主要介紹了Spring實戰(zhàn)之抽象Bean和子Bean定義與用法,結合實例形式分析了Spring抽象Bean和子Bean相關配置、定義與使用操作技巧,需要的朋友可以參考下2019-11-11

