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

How to intercept the first digits of a string in java

Release: 2019-11-21 13:38:47
Original
19956 people have browsed it

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)
Copy after login

or

public String substring(int beginIndex, int endIndex)
Copy after login

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("m.sbmmt.com");
 
        System.out.print("返回值 :" );
        System.out.println(Str.substring(4) );
 
        System.out.print("返回值 :" );
        System.out.println(Str.substring(4, 10) );
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template