Java String substring()
Substring is a part of the String. Java String substring() method returns a new string object from a given String.
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 ).
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.
How to extract first 4 character from a string?
How to extract last 8 characters from a String?