Using 'substring( )' method

substring( ) method is used to extract a portion from the actual string using the following two formats:

  • "StringText".substring(startIndex) -> Example: "SunShine".substring(3) -> It will extract the portion of string starting from Index 3 to the end of the string 
  • "StringText".substring(startIndex, endIndex) -> Example: "SuperSunShine".substring(5,8) -> It will extract the portion of string starting from Index 5 to the Index (8-1)
Lets implement this on Eclipse IDE:

1. Create 'substringDemo' class under any project as shown below:


2. Save and Run the 'substringDemo' class file
3. Observe that the output is displayed in the console as shown below:


Download this project:

Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)