Play Framework (java) - Treemap.zipWithIndex sorting order not preserved
<p>I'm using the Play Framework for java (2.5.4 with scala 2.11.8). I have a java.util.TreeMap (with a Comparable key) correctly sorted when getting out of my controller, but when using the zipWithIndex function on the view side, the sorting order is not preserve and the map is traversed in the insertion order. However, I need the index of the element in that loop too. Any idea why the zipWithIndex does not preserve the order (even if the javadoc says so), or any other suggestions to have loop counter in my scala template?</p>

<p>In the scala head, I have a variable defined as (the MyComparableKey implements the Comparable interface, no problem when doing a foreach on it, everything stays sorted).</p>

<pre><code>results : java.util.Map[MyComparableKey, java.util.List[MyValue]]
</code></pre>

<p>and inside de template, I'm using it with:</p>

<pre><code>@for(((k, values), i) &lt;- results.zipWithIndex) {
     @* the keys are traversed in insertion order *@
}
</code></pre>

<p>Thanks in advance.</p>