word.substring java code example
Example 1: how to do substring java
class Main {
public static void main (String[] args) {
String str = "Hello World!";
String firstWord = str.substring(0, 5);
String secondWord = str.substring(6, 11);
}
}
Example 2: substring java
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str = "This is tutorials point";
String substr = "";
substr = str.substring(8, 17);
System.out.println("substring = " + substr);
substr = str.substring(0, 8);
System.out.println("substring = " + substr);
}
}