Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
The substring() method in Java is used to extract a portion of a string based on specified starting and ending indexes. It returns a new string containing the extracted characters.
A position within an ordered collection of elements. In substring(), indexes are used to specify where the extraction should start and end within the original string.
In programming, immutable refers to objects whose state cannot be changed after they are created. Strings are immutable, meaning that when using substring(), a new string is created rather than modifying the original one.