velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <g...@4quarters.com>
Subject Re: Setting values in an array list
Date Tue, 06 Jan 2004 12:37:41 GMT
Additionallym, assuming that you really wanted to know how to add in  
the #foreach loop :

#set($array1 = [5,6,7,8,9,10])
#set($array2 = [])

#foreach($val in $array1)
   $array2.add($val * 2)
#end

geir


On Jan 5, 2004, at 1:41 PM, Will Glass-Husain wrote:

> 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
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
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