I have a string containing words separated by one or more blank characters (space, tab, etc.). I'm trying to write the most optimized procedure possible that outputs the string with the same words in the same order, but separated by only one space.
I'm trying this but I still have a problem:
public class Test {
public static void main(String args[]) {
String str = "word1, word2 word3@+word4?.word5.word6";
Stream<String> stream = Arrays.stream(input.split( "[, ?.@]+_" ));
.stream().collect(Collectors.joining(" "));
}
}
_? I'm guessing[, ?.@]+_should be[, ?.@_]+.s = s.replaceAll("\\P{Alnum}+", " ").trim()can do it.