Java String substring() method

Java String substring() method returns a part of the String.

Syntax:

Parameters:

startIndex  :  starting index

endIndex :  ending index

Returns:

It returns a specified String.

Throws:

StringIndexOutOfBoundsException if start index is negative value or end index is lower than starting index.

Java String substring() method example 1

Output:

Java String substring() Method Example 2

Output:

Java String substring() Method Example 3

Output:

Java String substring() Method Example 4

Output:

Leave a Comment