There are two substring () functions in String, as follows: one: String.substring (intstart) Parameter: Start: The index of the position to intercept returns: A string from start to end, for example: string str="Hello word!"; System. out. println (Str.substring (1)); System. out. println (Str.substring (3)); System. out. println (Str.substring (6) ; The result will be: Ello word!Lo Word!Ord!if start is greater than the length of the string, an out-of-bounds exception is thrown; II: string.substring (intBeginindex,intendIndex) Parameters: Beginindex Start position index EndIndex End position Index returns: a string from the Beginindex location to the EndIndex location for example: String str="Hello word!"; System. out. println (Str.substring (1,4)); System. out. println (Str.substring (3,5)); System. out. println (Str.substring (0,4) ; The result will be: ell lo hell if startindex and endindex are out of bounds, an out-of-bounds exception will be thrown.
Java substring intercept string