Language
Version: SE 8
Categories
-
User Program Communication
-
Variables
-
Control Flow
-
Object Oriented Programming
-
String Class
String Class
Substring in Java
A substring is a portion of an original string.
Syntax
String sub = bigString.substring(startIndex, endIndex); //endIndex is optional
Notes
Like an array, the first index of a string is 0.
Example
String phoneNumberSentence = "Phone number: 1-800 555 5555";
String phoneNumber = phoneNumberSentence.substring(14); //will return the phone number