How to extract certain substring from a string using Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Jan-2018 10:28:28
Advertisements