Duplicate words in a text Here is a simplified implementation to obtain the duplicate words in a text using lambda expressions.

public class FindDuplicateWordsInText {

    public static Set&lt;String&gt; findDuplicateWordsInText(String text) {
        String[] words = text.split(" ");
        Set&lt;String&gt; duplicatesRemovedSet = new HashSet&lt;&gt;();
        Set&lt;String&gt; duplicatesSet = Arrays.stream(words).filter(string -&gt; !duplicatesRemovedSet.add(string))
                .collect(Collectors.toSet());
        return duplicatesSet;
    }
}
Your use of the boolean return value of the Set.add() call is a clever way to check for your duplicates. The concept you have is good, and I can't think of a faster way.

Additionally, I like how you have used Interface-based types on the left-side of assignments Set&lt;String&gt; and the concrete classes on the right new HashSet&lt;&gt;() .... people often put the concrete type on the left too, and it's good to see that you did not.

In terms of the Java streaming API, though, I can't help but feel that you missed out on an opportunity to improve the process by streaming the split.... The Pattern class has a splitAsStream method which would reduce your latency on the first words....

As an aside, a word should probably be on a contiguous whitespace, not just a single space (i.e. "\\s+" instead of " ").

Here's your code done differently:

private static final Pattern SPACE = Pattern.compile("\\s+");

public static Set&lt;String&gt; findDuplicateWordsInText(String text) {
    Set&lt;String&gt; duplicatesRemovedSet = new HashSet&lt;&gt;();
    return SPACE.splitAsStream(text)
            .filter(string -&gt; !duplicatesRemovedSet.add(string))
            .collect(Collectors.toSet());
}