title: how to remove null values in string in java?
body: <p>here is my codings:</p>
  
  <pre><code>List&lt;String&gt; Rolelist1=new ArrayList&lt;String&gt;();
  StringBuilder b=new StringBuilder();
  for(String text1:Rolelist1) {
      b.append(text1).append(",");
  }
  
  Roletext1=b.toString().replaceAll(",$", "");
  </code></pre>
  
  <p>I want to convert a list into a string.
  for example</p>
  
  <pre><code>Rolelist=[A,B,C,B] into string Roletext1=A,B,C,D
  </code></pre>
  
  <p>it works. when my list is empty i will add elements again convert into string it shows <code>Roletext1=,E,f,g,h.</code> how can i get the output as E,F,G,h.pls help me</p>