How to access/get the size of an array/collection in velocity templates?

Danny picture Danny · Oct 13, 2011 · Viewed 47.7k times · Source

I am using velocity for email templates in my java/spring 3 app.
How could I get the size of an ArrayList added to the model from within the template.

Answer

JB Nizet picture JB Nizet · Oct 13, 2011

I've never used Velocity, but its VTL reference guide says that calling a method is done using $customer.getAddress() or ${purchase.getTotal()}. So I would use ${myArrayList.size()}.