Bad words detecting

Report a typo

You need to implement a method that returns a prepared stream for detecting bad words. The method has two parameters:

  • a text in which all words are divided by single whitespaces;

  • a list of all possible bad words.

The method must return a stream of all unique bad words present in the text, in lexicographical order (like in a dictionary).

Write a program in Java 17
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.*;

class BadWordsDetector {

private static Stream<String> createBadWordsDetectingStream(String text,
List<String> badWords) {
// write your code here
return Stream.of();
}

/* Do not change the code below */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] parts = scanner.nextLine().split(";");

// the first part is a text
String text = parts[0];

// the second part is a bad words dictionary
List<String> dict = parts.length > 1 ?
Arrays.asList(parts[1].split(" ")) :
Collections.singletonList("");

System.out.println(createBadWordsDetectingStream(text, dict).collect(Collectors.toList()));
}

}
___

Create a free account to access the full topic