java in substring () method

Interception string, java language usage

1、  public String substring(int beginIndex)

Returns a new string that is a substring of this string. The substring begins at the specified character index, it has been the end of this string.

Parameters: beginIndex - the index at the beginning of (including),

Returns: the specified sub- string,

Exception: If beginIndex is negative or greater than the length of the String object, then throws IndexOutOfBoundsException 

例  :"unhappy".substring(2)   returns"happy"

   "mybaby".substring(3)   returns"aby"

 

2、public String substring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string. The sub- string starting at the specified beginIndex, endIndex: endIndex 1-at the specified end.

Parameters: beginIndex - the index at the beginning of (including)

      Endindex index at the end (not included).
Returns: the child specified string .
Throws: If beginIndex is negative, or length greater than the length of the string, throws IndexOutOfBoundsException 
例:"hamburger".substring(3,8)  returns " burge"
  "smiles".substring(0,5) returns " smile"

Guess you like

Origin www.cnblogs.com/022414ls/p/11584037.html