How to access elements of array after using string.split in Velocity?

前端 未结 4 1794
旧巷少年郎
旧巷少年郎 2020-12-20 18:15

I am using Velocity Templating Language and currently have:

#set ( $stringList = $string.split(\",\") )

which works fine and splits the str

4条回答
  •  孤城傲影
    2020-12-20 18:53

    As of Velocity 1.6, all array references are now "magically" treated as if they are fixed-length lists. This means that you can call java.util.List methods on array references. So, if you have a reference to an array (let's say this one is a String[] with three values), you can do:

    $myarray.isEmpty()
    
    $myarray.size()
    
    $myarray.get(2) 
    
    $myarray.set(1, 'test')
    

    Source: http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html#methods

提交回复
热议问题