Issue with below snippet on boundary matchers regex (\b)

You need to create an alternation group out of the set with String.join(“|”, toDelete) and use as line = line.replaceAll(“\\b(?:”+String.join(“|”, toDelete)+”)\\b”, “”); The pattern will look like \b(?:end|something)\b See the regex demo. Here, (?:…) is a non-capturing group that is used to group several alternatives without creating a memory buffer for the capture (you do … Read more

Cartesian product of streams in Java 8 as stream (using streams only)

Passing the streams in your example is never better than passing Lists: private static <T> Stream<T> cartesian(BinaryOperator<T> aggregator, List<T>… lists) { … } And use it like this: Stream<String> result = cartesian( (a, b) -> a + b, Arrays.asList(“A”, “B”), Arrays.asList(“K”, “L”), Arrays.asList(“X”, “Y”) ); In both cases you create an implicit array from varargs … Read more