One of the basic principles for implementing the FreeMarker engine is that the data model can only be accessed in read-only mode. A value from a data model cannot be changed during template execution. One of the consequences concerns the Sequence type: FreeMarker can be used to create a sequence object in a literal way but, once it is created, the object cannot be changed (click here for more details).
Example:
<#assign seqVal = [1, 2, 3, 4, 5] /> <#list seqVal as aVal>...</#list> ${seqVal[1]} <#-- It is possible to browse the seqVal values or access a seqVal element but it is not easy to change a seqVal element or delete an element in seqVal --> <#-- Inefficient solution for changing an element (element in position 2 starting from 0) --> <#assign seqVal = seqVal[0..(2-1)] + [33] + seqVal[(2+1)..]/> <#-- Inefficient solution for changing an element (element in position 2 starting from 0)--> <#assign seqVal = [1, 2, 3, 4, 5] /> <#assign seqVal = seqVal[0..(2-1)] + seqVal[(2+1)..]/>
This function returns a Sequence-type object which has add/change/delete methods: this object is an encapsulation of the Java ArrayList object (click here for more details). Some methods from the ArrayList class can be used in a FreeMarker execution context: add/clear/contains/ensureCapacity/get/indexOf/isEmpty/lastIndexOf/remove/removeRange/set/size/subList/toArray.
Parameters
No parameter.
For example
<#assign newSeq = hardisCore.createArrayList() /> <#-- Use sequence built-in function with newSeq variable --> Size of newSeq:${newSeq?size} <#-- Use Java ArrayList "compatible" methods with newSeq variable --> IsEmpty:${newSeq.isEmpty()} <#assign textToAdd = "Hello"/> <#assign addOK = newSeq.add(textToAdd) />