The substring()
method in Java is used to extract a portion of a string. It is a part of the String
class and comes in two variations:
substring(int beginIndex)
: Returns a substring starting from the specified index to the end of the string.substring(int beginIndex, int endIndex)
: Returns a substring starting frombeginIndex
(inclusive) toendIndex
(exclusive).
Example:
The method is useful for string manipulation and processing.