velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Glass-Husain" <wgl...@forio.com>
Subject Re: Setting values in an array list
Date Mon, 05 Jan 2004 18:41:22 GMT
Hi Ryan,

#set creates an ArrayList, so you can use the List methods.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html

Try

#set ( $array1 = ['a', 'b', 'c', 'd', 'e'] )
#set ( $array2 = [] )
$array2.addAll($array1)

The one caveat is that the addAll method will display "true" as it has a
return value.  To remove this do

#set ($result = $array2.addAll($array1) )

WILL

----- Original Message ----- 
From: "Ryan Lea" <Ryan.Lea@Rightmove.co.uk>
To: <velocity-user@jakarta.apache.org>
Sent: Monday, January 05, 2004 9:22 AM
Subject: Setting values in an array list


> Hi all,
>
> This is potentially a daft question, BUT I couldn't find anything in the
> users list.  Is there a way to set values of an array from within a
foreach
> loop?
>
> Eg:
>
> #foreach ( $i in [0..50] )
>    ## somehow set position $i in the array to the corresponding value
> #end
>
> OR
>
> #set ( $array1 = ['a', 'b', 'c', 'd', 'e'] )
> #set ( $array2 = ['z', 'y', 'x', 'w', 'v'] )
>
> #foreach ( $value in $array1 )
>    ## somehow set the value in the array2 as the same as in array1
> #end
>
> Cheers
>
> Ryan
>
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs service.
> ________________________________________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message