Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split multiple delimiters in Java [closed]

How I can split the sentences with respect to the delimiters in the string and count the frequency of words ?

 String delimiters = "\t,;.?!-:@[](){}_*/";

My text file is:

Billy_Reeves

Smorz

Nationalist_Left_-_Youth

Ancient_Greek_units_of_measurement

Jiuting_(Shanghai_Metro)

Blodgett,_MO

Baekjeong

Matt_Brinkman

National_Vietnam_Veterans_Art_Museum
like image 802
Büşra GÜL Avatar asked Dec 20 '16 17:12

Büşra GÜL


People also ask

How do you split a string with two delimiters?

Using String. split() Method. The split() method of the String class is used to split a string into an array of String objects based on the specified delimiter that matches the regular expression.

How do I use StringTokenizer with multiple delimiters?

In order to break String into tokens, you need to create a StringTokenizer object and provide a delimiter for splitting strings into tokens. You can pass multiple delimiters e.g. you can break String into tokens by, and: at the same time. If you don't provide any delimiter then by default it will use white-space.

What does split \\ s+ do in Java?

split("\\s+") will split the string into string of array with separator as space or multiple spaces. \s+ is a regular expression for one or more spaces.

How do you do a double split in Java?

String s[]= txtArea. getText(). split("\\n");


1 Answers

Try with

split("\\t|,|;|\\.|\\?|!|-|:|@|\\[|\\]|\\(|\\)|\\{|\\}|_|\\*|/");

Also

Use String.split() with multiple delimiters

like image 90
AMB Avatar answered Sep 18 '22 13:09

AMB