title: Thymeleaf th:each adding coma between elements
body: <p>I have collection <code>X</code></p>
  
  <p>I iterate through it and write it like that:</p>
  
  <pre><code>&lt;span th:each="a, stat : ${X}"
        th:text="${X[__${stat.index}__].someProperty} + ','"&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>my other try was:</p>
  
  <pre><code>&lt;span th:each="a, stat : ${X}" th:for="|a${stat.index}|"
        th:text="${X[__${stat.index}__].someProperty} + ','"&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>unfortunately the output is the same.</p>
  
  <p>the output in the span is:</p>
  
  <pre><code>test1, test2, test3,
  </code></pre>
  
  <p>I want the output to be:</p>
  
  <pre><code>test1, test2, test3
  </code></pre>
  
  <p>without the comma at the end. How can I achieve that?</p>
  
  <p><strong>Solution:</strong></p>
  
  <ol>
  <li>Beware of The value of attribute <code>th:text</code> associated with an element type <code>span</code> <strong>must not contain the '&lt;' character</strong>.</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>&lt;span th:each="a, stat : ${X}"
        th:text=" ${X[__${stat.index}__].someProperty} +  (${stat.size-1 &gt; stat.index}? ',':'') "&gt;
  &lt;/span&gt;
  </code></pre>