Java String substring example

Previous
Next

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:

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog