The method is as follows:
public String substring(int beginIndex, int endIndex)
The first int is the index of the beginning, corresponding to the starting position in the String number.
The second is the cutoff index position, corresponding to the end position in String
1. The obtained string length is: endIndex - beginIndex;
2. Start from beginIndex to endIndex, start from 0, which does not include characters at the endIndex position.
like:
"hamburger".substring(4, 8) returns "urge""smiles".substring(1, 5) returns "mile"
Take the last three substrings of a string with length greater than or equal to 3, just 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 full content of the subString() method in Java String brought to you by the editor. I hope it will be helpful to everyone and support Wulin.com more~