Wednesday, 18 April 2018

FTL looping over map

FTL interating over a map :-

List<String> cityList1 = new ArrayList<String>();
cityList.add("Washington DC");

List<String> cityList2 = new ArrayList<String>();
cityList2.add("Berlin");
cityList2.add("Paris");
cityList2.add("Rome");

Map<String,List<String>> map = new HashMap<String,List<String>>();
map.put("US",cityList1);
map.put("UK",cityList2);

approach 1 :-
<#list map?keys as key>
    //looping map valuesfor the key we can set it to UI component
    <#list map[key] as city>
       <b> ${city} </b>
     </#list>
</#list>

approach 2 :-
<#list map?keys as key>
    //looping map valuesfor the key we can set it to UI component
    <#list map.values[key] as city>
       <b> ${city} </b>
     </#list>
</#list>

approach 3 :-
<#list map?keys as key>
    //looping map valuesfor the key we can set it to UI component
    <#list map?values[key] as city>
       <b> ${city} </b>
     </#list>
</#list>

approach 4 :-
<#list map.entrySet() as entry>
    //looping map valuesfor the key we can set it to UI component
    <#list entry.key as city>
       <b> ${city} </b>
     </#list>
</#list>

approach 5 :-
<#list map.entrySet() as entry>
     <#assign keyValue="${entry.key}">
    //looping map valuesfor the key we can set it to UI component
    <#list keyValue as city>
       <b> ${city} </b>
     </#list>
</#list>

approach 6 :-
<#list map?keys as key>
    <#assign keyValue="map[key]">
    //looping map valuesfor the key we can set it to UI component
    <#list keyValue as city>
       <b> ${city} </b>
     </#list>
</#list>

No comments:

Post a Comment

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...