Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am iterating a java list in freemarker , but I want commas in between the words. Here's my code

<#list key_list[key] as value >${value?js_string}, </#list>

This gives me output as

a,b,c,d,

I want the output in this format:(No comma in the end)

a,b,c,d

How can I get that

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
720 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you use FreeMarker version 2.3.23 or higher, sep tag will work for you:

<#list users as user>
    ${user}<#sep>, </#sep>
</#list>

OR even shorter than that:

<#list users as user>${user}<#sep>, </#list>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...