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

前端 未结 4 1765
旧巷少年郎
旧巷少年郎 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:40

    It works when I convert the array to a List using Arrays.asList() and then use methods from List to access elements.

    I add the following to the context:

    context.put("arrays", Arrays.class);
    

    In velocity template I use:

    #set ( $array = $getarray.getArray() )
    
    $arrays.asList($array).get(0)
    

    With a String-Array as follows

    new String[] {"test1", "test2", "test3", "test4"};
    

    I get the expected output:

    test1
    

提交回复
热议问题