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

Add to Slack

< Split String   |   String Representation >

© 2019 SyntaxDB. All Rights Reserved.