Java String substring() method with Index


In this program, You will learn how to implement the String substring() method with Index in java.


if (a.substring(index)) { 
    //statement
}

Example: How to implement the String substring() method with Index in java.

import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String a, b;

        System.out.print("Enter a string value:");
        a = sc.nextLine();

        b = a.substring(3, 6);

        System.out.print("Substring value:" + b);

    }
}

Output:

Enter a string value:Xiith.com
Substring value:th.