Velocity Template #foreach & #end loop with Java List

To create a foreach loop to go iterate through a list of items :

#set($campaigns = ["one", "two", "three"])

#foreach($campaign in $campaigns)

  List Item: $campaign

#end

-----------------------------------

Java code:

List> campaings = new ArrayList>();

List c1 = new ArrayList();

c1.add("1a");

c1.add("2a");

c1.add("3a");

c1.add("4a");

campaings.add(c1);

List c2 = new ArrayList();

c2.add("1b");

c2.add("2b");

c2.add("3b");

c2.add("4b");

campaings.add(c2);

map.put("campaigns", campaings);

Example of how you loop thru the above Java List of List(s) of String(s) using #foreach loops:
 


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles