Substring In Java Example
Chapter:
String Handling
Last Updated:
11-06-2017 14:13:39 UTC
Program:
/* ............... START ............... */
public class JavaSubStringExample {
public static void main(String args[]) {
String Str = new String("Welcome to JavaScan.com");
System.out.print("Return Value :");
System.out.println(Str.substring(10));
System.out.print("Return Value :");
System.out.println(Str.substring(10, 15));
}
}
/* ............... END ............... */
Output
Return Value : JavaScan.com
Return Value : Java
Notes:
-
String substring(int beginIndex): Returns the substring starting from the specified index(beginIndex) till the end of the string.
- For e.g. "JavaScan".substring(2) would return "vaScan".
- public String substring(int startIndex): This method returns new String object containing the substring of the given string from specified startIndex (inclusive).
- public String substring(int startIndex, int endIndex): This method returns new String object containing the substring of the given string from specified startIndex to endIndex.
Tags
substring(), Java