On substring () method in Java string

The method is as follows:

The first int is the starting index, corresponding to the starting position in the string number,

The second is the end index position, which corresponds to the end position in the string

1. The obtained string length is: endindex - beginindex;

2. Starting from beginindex and ending at endindex, starting from 0, excluding the characters at the endindex position

For example:

Take the last three substrings of string a with a length greater than or equal to 3, and only a.substring (a.length() - 3, a.length());

The specific instructions in the manual are as follows:

substring

public String substring(int beginIndex,int endIndex) Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Examples:

"hamburger". substring(4,8) returns "urge" "smiles". substring(1,5) returns "mile"

Parameters:

beginIndex - the beginning index,inclusive. endIndex - the ending index,exclusive.

Returns:

the specified substring.

Throws:

indexoutofboundsexception - if the beginIndex is negative,or endIndex is larger than the length of this String object,or beginIndex is larger than endIndex

The above is the whole content of substring () method in Java string brought by Xiaobian. I hope it can help you and support a lot of programming tips~

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>