+substring(beginIndex: int, endIndex: int); return type String
import java.lang.String;
class subStringstartend{
public static void main(String[] arg){
String str1="Welcome to Java";
String str2=str1.substring(3,11);
System.out.println("str1: "+str1);
System.out.println("str2=str1.substring(3,11): "+str2);
}
}
Output: str1: Welcome to Java
str2=str1.substring(3,11): come to
Note: If beginIndex is endIndex, substring(beginIndex, endIndex) return an empty string with length 0. If beginIndex > endIndex, it would be run time error.
import java.lang.String;
class subStringstartend{
public static void main(String[] arg){
String str1="Welcome to Java";
String str2=str1.substring(11,2);
System.out.println("str1: "+str1);
System.out.println("str2=str1.substring(11,2): "+str2);
}
}
This code will compile normally but show error at run time.......
class subStringstartend{
public static void main(String[] arg){
String str1="Welcome to Java";
String str2=str1.substring(3,11);
System.out.println("str1: "+str1);
System.out.println("str2=str1.substring(3,11): "+str2);
}
}
Output: str1: Welcome to Java
str2=str1.substring(3,11): come to
Note: If beginIndex is endIndex, substring(beginIndex, endIndex) return an empty string with length 0. If beginIndex > endIndex, it would be run time error.
import java.lang.String;
class subStringstartend{
public static void main(String[] arg){
String str1="Welcome to Java";
String str2=str1.substring(11,2);
System.out.println("str1: "+str1);
System.out.println("str2=str1.substring(11,2): "+str2);
}
}
This code will compile normally but show error at run time.......