Java String substring example

String’s substring method is used to fetch part of a String.It returns a new String which is substring of given String. substring is nothing but subset of given String.

There are two overloaded methods for substring.

Method Signature:

It returns a new String which is substring of given String from specified startIndex(Inclusive)

It returns a new String which is substring of given String from specified startIndex(Inclusive) to endIndex(Exclusive)

String’s index always starts with 0. In case of substring method, startIndex is always inclusive and endIndex is exclusive

String substring Example:

When you run above program, you will get below output:

Add Comment