How to extract certain substring from a string using Java?


You can extract a substring from a String using the substring() method of the String class to this method you need to pass the start and end indexes of the required substring.

Example

Live Demo

public class Substring {
   public static void main(String args[]) {

      String str = "Welcome to Tutorialspoint";
      String sub = str.substring(10, 25);
      System.out.println(sub);
   }
}

Output

Tutorialspoint

Updated on: 20-Feb-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements