In java, you can use the substring() method to intercept the first few digits of a string.
The substring() method returns the substring of a string.
Syntax:
public String substring(int beginIndex)
or
public String substring(int beginIndex, int endIndex)
Parameters:
beginIndex -- Starting index (inclusive), the index starts from 0.
endIndex -- End index (not included).
Return value
Substring.
Example:
public class Test { public static void main(String args[]) { String Str = new String("www.php.cn"); System.out.print("返回值 :" ); System.out.println(Str.substring(4) ); System.out.print("返回值 :" ); System.out.println(Str.substring(4, 10) ); } }
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of How to intercept the first digits of a string in java. For more information, please follow other related articles on the PHP Chinese website!