0

is the any way adding values to an arraylist at a certain position (index)?

The following code works fine (but add the element at the end of the array):

#set($arr = [])
#if ($arr.add('A')) #end

I also tried

#set($arr = [])
#if ($arr.add(1,'A')) #end

but that doesn't work. Although the Java class ArrayList does support both ways... Any help highly appreciated.

BR, Andreas

Andreas
  • 53
  • 7
  • Possible duplicate of [Create and iterate through an array in Velocity Template Language](https://stackoverflow.com/questions/6123691/create-and-iterate-through-an-array-in-velocity-template-language) – Ori Marko Jun 15 '18 at 10:09
  • Thx for referencing the other thread but I don't think it's the same. My request is about adding element to an array at a certain position (index). I just wonder that it seems possible retrieving a value from an array based on the index with $arr.get($idx) but it seems not possible adding a value at a given position inside the array... Is this really the case? – Andreas Jun 15 '18 at 11:17

0 Answers0