The substring () method in the Java string

Source: Internet
Author: User

Here's how:

Public String substring (int beginindex, int endIndex) The first int is the starting index, corresponding to the start position in the string number, and the second is the cutoff index position, corresponding to the end position in string 1, The string length obtained is: endindex-beginindex;2, starting from Beginindex, to the end of the EndIndex, starting from 0, which does not include the endIndex position of the word such as: "Hamburger". Substring (4, 8 ) returns "Urge"   "smiles". Substring (1, 5) returns "Mile" takes the first three substrings of string A with a length greater than or equal to 3, just a.substring (A.length ()-3, A.length ()) The;  manual is specified as follows: substringpublic 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 thThe length of this String object, or beginindex is larger than EndIndex.

Substring () method in a string of Java

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.