List of String in Freemarker

freemarkerlist

I have a list of string in java code:

List<String> keywords = new ArrayList<String>();
keywords.add("Apple");
keywords.add("Banana");

and I would like to display the keywords using Freemarker:
Apple, Banana

How to do that?

PS:
I read through the manual and found some articles suggesting using <#list>, but the output is:
Apple

Banana

Best Answer

If you want a comma-separated list, you can use the following:

<#list seq as x>
   ${x_index + 1}. ${x}<#if x_has_next>,</#if>
</#list>  

see: http://freemarker.org/docs/ref_directive_list.html#pageTopTitle