How to split a String in java

In this post, we will see how to split a String by delimiter in java. Sometimes, we need to split a String by delimiter
for example: while reading a csv file, we need to split string by comma(,).

We will use String class’s split method to split a String. This split(regex)  takes a regex as a argument,  so we need to escape some regex special character for example dot(.).  Split method returns a array of String.

Example:

When you run above progrm, you will get following output:

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *