title: Checking range of List in forEach lambda loop Java 8
body: <p>I want to learn how I can check the range of a list in java 8.</p>
  
  <p>For example,</p>
  
  <p>My Code:</p>
  
  <pre><code>    List&lt;String&gt; objList = new ArrayList&lt;&gt;();
      objList.add("Peter");
      objList.add("James");
      objList.add("Bart");
  
      objList.stream().map((s) -&gt; s + ",").forEach(System.out::print);
  </code></pre>
  
  <p>My out come is</p>
  
  <pre><code>    Peter,James,Bart,
  </code></pre>
  
  <p>but I want to know how I can get rid of the last ,</p>
  
  <p>Note: I know I must use filter here , yet I do not know how and I know there is another way to solve this which is as follows </p>
  
  <pre><code>String result = objList.stream()
      .map(Person::getFirstName)
      .collect(Collectors.joining(","));
  </code></pre>
  
  <p><strong>yet I want to know how to check the range and get rid of , in my first code.</strong> </p>