I have in java this HashMap:
HashMap<String, String> map = new HashMap<String, String>();
map.put("k1", "3");
map.put("k2", "4");
map.put("k3", "2");
map.put("k4", "6");
map.put("k5", "1");
map.put("k6", "5");
I print with freemarker template in this mode:
<#list map?values as v>
${v} -
</#list>
but it prints in this order:
2 - 6 - 1 - 5 - 3 - 4
I would like to print in this order:
1 - 2 - 3 - 4 - 5 -6
how can I sort values with with freemarker template?
Try this:
<#list map?values?sort as v>
${v} -
</#list>
Notice the use of the sort
builtin for the sequence of values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With