I want to replace multiple character in given string with a single space.
eg: He is a very very good boy, isn't he?
Should be replaced to
He
is
a
very
very
good
boy
isn
t
he
My code is
String str = "He is a very very good boy, isn't he?"
String str2 = str.replaceAll("![,?.\_'@+] +"," ");
String []tokens = str2.split(" +");
for(int i = 0; i< tokens.length; i++)
System.out.println(tokens[i]);
But the output is
He
is
a
very
very
good
boy,
isn't
he?
Please correct my code if possible or suggest a new one.