Split String with Dot (.) in Java


Let’s say the following is our string.

String str = "This is demo text.This is sample text!";

To split a string with dot, use the split() method in Java.

str.split("[.]", 0);

The following is the complete example.

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       String str = "This is demo text.This is sample text!";
       String[] res = str.split("[.]", 0);
       for(String myStr: res) {
          System.out.println(myStr);
       }
    }
}

Output

This is demo text
This is sample text!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements