Check out example codes for "substring in java". It will help you in understanding the concepts better.

Code Example 1

class Main {
  public static void main (String[] args) {
    
    String str = "Hello World!";
    
    String firstWord = str.substring(0, 5);
    //two parameters are start and end index: (inclusive, non-inclusive)
    
    String secondWord = str.substring(6, 11);
    
    //firstWord has string "Hello"
    //secondWord has string "World"
  }
}

Code Example 2

String s = "Let's Get This Bread";

String subString = s.substring(6, 9);
				// (start index inclusive, end index exclusive)

// subString == "Get"

Code Example 3

class scratch{
    public static void main(String[] args) {
        String hey = "Hello World";
        System.out.println( hey.substring(0, 5) );
        // prints Hello;
    }
}

Code Example 4

// Initializing String 
        String Str = new String("Welcome to geeksforgeeks"); 
  
        // using substring() to extract substring 
        // returns geeksforgeeks 
        System.out.print("The extracted substring is : "); 
        System.out.println(Str.substring(10));

Code Example 5

int indexOf(char c)
// Accepts character as argument, Returns index of 
// the first occurrence of specified character

Code Example 6

// Java code to demonstrate the 
// working of substring(int begIndex) 
public class Substr1 { 
    public static void main(String args[]) 
    { 
  
        // Initializing String 
        String Str = new String("Welcome to geeksforgeeks"); 
  
        // using substring() to extract substring 
        // returns geeksforgeeks 
        System.out.print("The extracted substring is : "); 
        System.out.println(Str.substring(10)); 
    } 
}

Learn ReactJs, React Native from akashmittal.com