title: How to print a list by adding a new line after every 3rd element in a list in java lambda expression?
body: <p>Suppose I have a list as below</p>
  
  <pre><code>Collection&lt;?&gt; mainList = new ArrayList&lt;String&gt;();
  mainList=//some method call//
  </code></pre>
  
  <p>Currently, I am displaying the elements in the list as </p>
  
  <pre><code>System.out.println(mainList.stream().map(Object::toString).collect(Collectors.joining(",")).toString());
  </code></pre>
  
  <p>And I got the result as</p>
  
  <pre><code>a,b,c,d,e,f,g,h,i
  </code></pre>
  
  <p>How to print this list by adding a new line after every 3rd element in a list in   java, so that it will print the result as below</p>
  
  <pre><code>a,b,c
  d,e,f
  g,h,i
  </code></pre>
  
  <p>Note: This is similar to <em><a href="https://stackoverflow.com/questions/22746198/how-to-add-newline-after-every-3rd-element-in-ArrayList-in-java">How to Add newline after every 3rd element in arraylist in java?</a></em>.But there formatting the file is done while reading itself.
  I want to do it while printing the output.</p>