Home  >  Article  >  Java  >  How to intercept the first digits of a string in java

How to intercept the first digits of a string in java

尚
Original
2019-11-21 13:38:4719882browse

How to intercept the first digits of a string in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn