0

Given this string we want count word occurrence (term frquency)

String input="this a test of tests",

This will split our phrase into words

Stream<String> stream = Stream.of(input.toLowerCase().split("\\s")).parallel();

How to edit a the stream values ,as follow : if a element of the stream ends with an "s" character then remove it.

1
  • 3
    use filter operation on your stream. Commented Apr 28, 2016 at 16:17

1 Answer 1

1

Try this.

    String input="this a test of tests";
    Map<String, Long> map = Stream.of(input.toLowerCase().split("\\s")).parallel()
        .map(s -> s.replaceFirst("s$", ""))
        .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    System.out.println(map);

result:

{a=1, test=2, thi=1, of=1}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.