title: Cleaning a list of data in Java8
body: <p>For cleaning a list of data, I have created a method which accepts the list of data and list of cleaning operation to be performed.</p>
  
  <pre><code>public &lt;T&gt; List&lt;T&gt; cleanData(List&lt;T&gt; data, List&lt;Function&lt;T, T&gt;&gt; cleanOps) {
      List&lt;T&gt;dataNew=data.stream().map((str) -&gt; {
          T cleanData = str;
          for(Function&lt;T,T&gt; function:cleanOps) {
              cleanData=function.apply(cleanData);
          }
          return cleanData;
      }).collect(Collectors.toList());
      return dataNew;
  }
  </code></pre>
  
  <p>The issue here is that we are creating the whole list again as <code>Collectors.toList()</code> returns a new list.
  Can we achieve the same result without using the extra space?</p>
  
  <p>Below is the code for invocation:</p>
  
  <pre><code>public void processData() {
      List&lt;Function&lt;String, String&gt;&gt; cleanOps = new ArrayList&lt;&gt;();
      cleanOps.add(String::toLowerCase);
      cleanOps.add(str -&gt; str.replaceAll(" ", ""));
      List&lt;String&gt; data = new ArrayList&lt;&gt;();
      data.add("John Doe");
      data.add("Jane Doe");
      System.out.println(Arrays.toString(cleanData(data, cleanOps).toArray()));
  }
  </code></pre>