How to use Java String.split() method to split a string by dot?

Java 8Object Oriented ProgrammingProgramming

The split() method of the String class is used to split the given string around matches of the given regular expression. To split a string by dot pass a dot by placing double escape characters as "\\."

Example

Live Demo

public class Data {
   public static void main(String args[]) {
      String Str = new String("Welcome.to.Tutorialspoint.com");
      System.out.println("Return Value :" );
      for (String retval: Str.split("\\.")) {
         System.out.println(retval);
      }
   }
}

Output

Return Value :
Welcome
to
Tutorialspoint
com
raja
Published on 12-Feb-2018 07:10:05
Advertisements