KaiquanMah's picture
Create 12a. Substrings
1c7978b verified
raw
history blame
603 Bytes
s.substring(int initialindex), which returns a substring of the string s FROM the GIVEN INDEX TO THE END of the string
s.substring(int startindex, int endindex), which returns the substring 's' of the string BETWEEN the given INDICES
- from startindex
- UP TO BUT NOT INCLUDING endindex
Examples on using substrings:
String str = "abcdefghijk";
// five first characters
System.out.println(str.substring(0,5));
// Characters from third character onward
System.out.println(str.substring(2));
// Characters 3-6
System.out.println(str.substring(3, 7));
Program outputs:
abcde
cdefghijk
defg