title: Grouping and replacing groups inside stream, Java 8
body: <p>I have such task: in sorted stream of Strings, change all groups of 3 same strings to one that contains a capital letter (use java 8 stream API). Example: </p>
  
  <pre><code>input = {"a","a","b","b","b","c"} 
  
  output = {"a","a","B","c"}
  </code></pre>
  
  <p>I can count same Strings in stream but I don't understand how to replace a group, without extra iterations. All I have now is: </p>
  
  <pre><code>Map&lt;String, Long&gt; result = Stream.of("a","a","b","b","b","c")
              .collect(Collectors.groupingBy(Function.identity(), 
                      LinkedHashMap::new, Collectors.counting()));
  
  System.out.println(result);
  </code></pre>
  
  <p>//current output: {a=2, b=3, c=1}</p>