1String s = "Let's Get This Bread";
2
3String subString = s.substring(6, 9);
4 // (start index inclusive, end index exclusive)
5
6// subString == "Get"
1"Chaitanya".substring(2)//=>aitanya
2//make me a SubString starting from index 2 to the end of the string!
1class Main {
2 public static void main (String[] args) {
3
4 String str = "Hello World!";
5
6 String firstWord = str.substring(0, 5);
7 //two parameters are start and end index: (inclusive, non-inclusive)
8
9 String secondWord = str.substring(6, 11);
10
11 //firstWord has string "Hello"
12 //secondWord has string "World"
13 }
14}
1class scratch{
2 public static void main(String[] args) {
3 String hey = "Hello World";
4 System.out.println( hey.substring(0, 5) );
5 // prints Hello;
6 }
7}