title: Java 8 Streams modify collection values
body: <p>Using the stream API; once the relevant data has been filtered I'd like to edit the data being collected. Here is the code so far:</p>
  
  <pre><code>  String wordUp = word.substring(0,1).toUpperCase() + word.substring(1);
    String wordDown = word.toLowerCase();
  
    ArrayList&lt;String&gt; text = Files.lines(path)
          .parallel() // Perform filtering in parallel
          .filter(s -&gt; s.contains(wordUp) || s.contains(wordDown) &amp;&amp;  Arrays.asList(s.split(" ")).contains(word))
          .sequential()
          .collect(Collectors.toCollection(ArrayList::new));
  </code></pre>
  
  <p><strong>Edit</strong> The code below is awful and I am trying to avoid it.(It also does not entirely work. It was done at 4am, please excuse it.)</p>
  
  <pre><code>    for (int i = 0; i &lt; text.size(); i++) {
          String set = "";
          List temp = Arrays.asList(text.get(i).split(" "));
          int wordPos = temp.indexOf(word);
  
          List&lt;String&gt; com1 = (wordPos &gt;= limit) ? temp.subList(wordPos - limit, wordPos) : new ArrayList&lt;String&gt;();
          List&lt;String&gt; com2 = (wordPos + limit &lt; text.get(i).length() -1) ? temp.subList(wordPos + 1, wordPos + limit) : new ArrayList&lt;String&gt;();
          for (String s: com1)
              set += s + " ";
          for (String s: com2)
              set += s + " ";
          text.set(i, set);
      }
  </code></pre>
  
  <p>It's looking for a particular word in a text file, once the line has been filtered in I'd like to only collect a portion of the line every time. A number of words on either side of the keyword that is being searched for.</p>
  
  <p>eg:</p>
  
  <p><code>keyword = "the"</code>
  <code>limit = 1</code></p>
  
  <p>It would find: <code>"Early in the morning a cow jumped over a fence."</code></p>
  
  <p>It should then return: <code>"in the morning"</code></p>
  
  <p>*P.S. Any suggested speed improvements will be up-voted.</p>