title: How to run a function on each element in a list in JAVA?
body: <p>I would like to know if it's possible to use streams to call a function on each element in a list and to <strong><em>modify</em></strong> its value as well.</p>
  
  <p>Let's say I have a list of integers: <code>List&lt;Integer&gt; list = Arrays.asList(1,2,3);</code></p>
  
  <p>And a method that increments every number by one:</p>
  
  <pre><code>public static Integer plusOne(Integer n){
      return n + 1;
  }
  </code></pre>
  
  <p>This is what I used to call the function on each element and modify the original list:</p>
  
  <pre><code>for (int i = 0; i &lt; list.size(); i++){
      list.set(i, plusOne(list.get(i)));
  }
  </code></pre>
  
  <p>However, I wanted to know if there is a shorter way of writing this using streams?</p>
  
  <p>I tried using:</p>
  
  <pre><code>list.stream()
      .forEach(e -&gt; plusOne(e));
  </code></pre>
  
  <p>But it doesn't seem to change the original list, nor return anything... If it's impossible to change the original list using streams, how can I at least get a new modified copy of the list?</p>
  
  <p>The output, by the way, should be a list of (2,3,4) after calling the function on the list.</p>