Java method of intercepting the first digits of a string:
Recommendation: java video tutorial
1. Through subString( ) method to perform string interception.
subString provides different interception methods through different parameters
Pass in 2 index values
String sb = "bbbdsajjds"; sb.substring(0, 4);
Start from index number 0 and end at index 4 (and do not include Index 4 interception is included, which means that the actual interception is characters 0 to 3);
The running results are as follows:
bbbd
2. Through the method provided by StringUtils
StringUtils.substringBefore(“dskeabcee”, “e”);
/The result is: dsk/
Here, the first "e" is used as the standard.
StringUtils.substringBeforeLast(“dskeabcee”, “e”)
The result is: dskeabce
The last "e" shall prevail here.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of How to get the first few digits of a string in java. For more information, please follow other related articles on the PHP Chinese website!