You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/06/14 14:17:02 UTC

Re: How to get list of Hash keys?

Patrick Saunders wrote:
> 
> G'day all,
> I think I've even asked this question before.. but I'm having
> trouble putting my Java brain on these days.. maybe too much
> PLSQL & ksh.. anyway, question follows:
> 
> How do I get a list of keys in a hashMap so that I
> can iterate over them?
> 
> Would a method call like this work?  (Ignoring the fact I'm not
> in Velocity context ).
> 
>   list =    myHash.entrySet().toArray()

Those are entries.  Try keySet()

example in a template :

#foreach($key in $hashtable.keySet() )
  key = $key  value = $hashtable.get($key)
#end


where $hashtable is a Hashtable (of course).  (HashMap works as well)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!