java substring code example
Example 1: java substring
String s = "Let's Get This Bread";
String subString = s.substring(6, 9);
Example 2: 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 3: 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 4: 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);
}
}
Example 5: String... java
func();
func("arg1", "arg2", "arg3");
String[] args = new String[]{"arg1", "arg2", "arg3"}
func(args);
void func(String... args);
Example 6: java get substring
String n = "hello there general kenobi";
System.out.println(n.substring(6, 11));