On the substring () method in Java string _java

Source: Internet
Author: User

The method is as follows:

Public String substring (int beginindex, int endindex)

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

The second is the cutoff index position, corresponding to the end position in string

1, obtained the length of the string: Endindex-beginindex;

2, starting from the Beginindex, to the end of Endindex, starting from 0, which does not include endindex position characters

Such as:

"Hamburger". Substring (4, 8) returns "Urge"
"smiles". Substring (1, 5) returns "Mile"

Take the second three substrings of a string a 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, 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 be larger than the length of this String object, or Beginindex is larger than endindex

The above is a small series for everyone to talk about Java String substring () method of the whole content, I hope to help you, a lot of support cloud Habitat Community ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.