title: get a comma separated string using java stream
body: <p>I have the following code using java <code>Stream</code>.</p>
  
  <p>I am trying the get the function to build a string of value: "a,b" in this case.
  however, the output (<code>separatedByComma</code> in this case) is always "b".</p>
  
  <p>Could somebody shed some light please?</p>
  
  <pre><code>@Test
  public void testJoin() {
      List&lt;MOccS&gt; occList = new ArrayList&lt;&gt; (  );
      MOccS mOccS = new MOccS ();
      mOccS.setOccSCd ( "1" );
      mOccS.setOccSNm ( "a" );
      occList.add ( mOccS );
  
      MOccS mOccS2 = new MOccS ();
      mOccS2.setOccSCd ( "2" );
      mOccS2.setOccSNm ( "b" );
      occList.add ( mOccS2 );
  
  
      List&lt;String&gt; strings = new ArrayList&lt;&gt; (  );
      strings.add ( "1" );
      strings.add ( "2" );
  
      String separatedByComma = "";
      for(String word: strings) {
          separatedByComma = occList.stream ()
                                    .filter ( occ -&gt; word.equalsIgnoreCase ( occ.getOccSCd () ) )         
                                    .map ( occ -&gt; occ.getOccSNm () )
                                    .collect ( Collectors.joining ( "," ) );
       }
  
       System.out.println (separatedByComma);
  }
  
  
  class MOccS{
      String occSCd;
      String occSNm;
      ...
      getter/setter
      ...
  }
  </code></pre>