You can split a string by dot using the following regex inside the String.split() method. Here, we need to use double backslash before dot(.) to escape it else it would split the string using any character.
str.split("\\.");
Program to split string by dot
public class JavaExample{ public static void main(String args[]){ //String that contains dot characters String str = "Text1.Text2.Text3.Text4"; //split the given string by using dot (.) as delimiter String[] strArray = str.split("\\."); //prints substrings after split for(String s: strArray){ System.out.println(s); } } }
Output:
Related java guides:
Main Article: String in Java