Get Substring of Given String in Java
Overview
In this tutorial, we will learn to extract or get substring of given String in a Java program.
Sample Code
Sample Java program to show the use of the substring() method.
/******************************************* * Java String substring() method Example * Java Tutorials - www.TestingDocs.com * ********************************************/ public class JavaSubStringExample { public static void main(String args[]) { String str= new String("www.TestingDocs.com Software Testing Website "); System.out.println("Substring upto index 20:"); System.out.println(str.substring(0,20)); System.out.println("Substring from index 20 and ending at 45:"); System.out.println(str.substring(20, 45)); } }