Thursday, April 22, 2021

REMINDER: substring - ending index is exclusive! => "S".equals("String".substring(0,1))

REMINDER: substring - ending index is exclusive! => "S".equals("String".substring(0,1))


"north".substring(0,1) => "n"
"north".substring(1,2) => "o"
"north".substring(1,3) => "or"
 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"

Signature:
public String substring(int startIndex)  
and  
public String substring(int startIndex, int endIndex)  
If you don't specify endIndex, java substring() method will return all the characters from startIndex.


No comments: