title: Remove AtomicInteger counter from stream
body: <p>is it possible to achieve the same functionality with the code below but without using the AtomicInteger counter, or as a matter of fact, no counter at all? This code controls the order in which certain areas in the front end of my project can be completed. If <code>isAutomaticDataEnabled(name)</code> is <code>true</code>, then the first element from the <code>dataList</code> - the IData elements in dataList are converted to Data and then a list of Data is sent back as an HTTP response, to the front end -   must be handled and then only after it has been handled the second item in the dataList will become available for processing and modification, hence why I added that counter. But I would like to keep the stream and yet somehow achieve the same result, as to when I have the counter. Can it somehow be removed and the stream modified in a way that will allow me to not alter my functionality and to not go back at using conventional for loop?</p>
  <p>Thank you</p>
  <pre><code>public List&lt;Data&gt; toData(List&lt;Idata&gt; dataList, String name) {
      AtomicInteger counter = new AtomicInteger(0);
      List&lt;Data&gt; data= dataList.stream().sorted().map(input -&gt; {
          if (input == null) {
              throw new IllegalArgumentException(&quot;input cannot be null for IData&quot;);
          }
          if (counter.get() == 0 &amp;&amp; !input.getStatus().equals(DataStatus.COMPLETE)) {
              counter.compareAndSet(counter.get(), counter.get() + 1);
              return populateDataFields(input,true); //JUST a method that populates fiedls
          }
          if (isAutomaticDataEnabled(name)) {
              return populateDataFields(input,false);
          }
          return populateDataFields(input,true);
      }).collect(Collectors.toList());
      counter.set(0);
      return data;
  }
  </code></pre>