Java String substring()
Substring is a part of the String. Java String substring() method returns a new string object from a given String.
Syntax
String str = "Java String Tutorial";
String newStr = str.substring(5);
The above code returns "String Tutorial". That means the substring function extract the new string from 5th character (start index 5 ).
Example
Output
Syntax
The above method creates a new String object containing the contents of the existing String between two indices.
The above code returns "String", that means it extract the string from the 5th character to 11th character.