You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chirantan Kundu <ch...@anshinsoft.com> on 2002/12/20 08:03:55 UTC
Access array elements via index
Hi,
I'm a newcomer to Velocity. Could anybody please tell me how to access
an element in an array via its index?
For example, my java code returns an array of strings. I can access the
values in velocity template using:
#foreach($value in $returnedArray)
But how can I access something like $returnedArray[0] (this syntax
doesn't work) ? I also tried $returnedArray.get(0) but that doesn't work
either.
Any help would be appreciated.
Thanks.
Chirantan
Re: Access array elements via index
Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On Friday, December 20, 2002, at 02:03 AM, Chirantan Kundu wrote:
> Hi,
> I'm a newcomer to Velocity. Could anybody please tell me how to access
> an element in an array via its index?
> For example, my java code returns an array of strings. I can access
> the
> values in velocity template using:
> #foreach($value in $returnedArray)
> But how can I access something like $returnedArray[0] (this syntax
> doesn't work) ? I also tried $returnedArray.get(0) but that doesn't
> work
> either.
> Any help would be appreciated.
> Thanks.
> Chirantan
>
We don't have array access syntax $foo[$i] in velocity.
They best way is to put your array of strings in an ArrayList (or any
implementation of List) and then .get($i) will work.
--
Geir Magnusson Jr 203-355-2219(w)
Adeptra, Inc. 203-247-1713(m)
geirm@adeptra.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>