Object [] Regular object array, not much needs to be said here. Velocity will internally wrap your array in a class that provides an Iterator interface, but that shouldn't concern you as the programmer, or the template author. Of more interest, is the fact that Velocity will now allow template authors to treat arrays as fixed-length lists (as of Velocity 1.6). This means they may call methods like size(), isEmpty() and get(int) on both arrays and standard java.util.List instances without concerning themselves about the difference.
# 1 楼答案
引自the developer guide:
因此,使用
size()
在java.util.List
和java数组上同样有效# 2 楼答案
我从未使用过Velocity,但它的VTL reference guide表示调用方法是使用
$customer.getAddress()
或${purchase.getTotal()}
完成的。所以我会使用${myArrayList.size()}
# 3 楼答案
可以像访问任何其他对象一样访问集合,因此
$collection.size()
将包含一个值数组special cased的行为类似于
List
,因此尽管$array.length
不起作用,但$array.size()
起作用在旧版本的Velocity(1.6之前)中,您将使用^{} 和^{}