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



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

Advertisements