get part of string java code example
Example 1: how to substring in java
class scratch{
public static void main(String[] args) {
String hey = "Hello World";
System.out.println( hey.substring(0, 5) );
}
}
Example 2: 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 3: java get substring
String n = "hello there general kenobi";
System.out.println(n.substring(6, 11));