You can iterate a java map in many ways.

java.util.Map<Object, Object> hashMap = new ...;
java.util.Iterator<Object> iter = hashMap.keySet().iterator();
while(iter.hasNext()) {
    Object key =;
    Object value = hashMap.get(key);
    //do something with key and object

Template the above code by your type.

On Fri, Mar 26, 2010 at 8:41 AM, Jon <> wrote:
Hi all,

I feel like this question is probably a FAQ, but I haven't been able to turn up any documentation--please point me in the right direction if there's anything relevant.

I've got a class in Java that extends java.util.HashMap:

class Foo extends HashMap { /* stuff */ }

I'm using Jython in an embedded manner to pass instances of Foo to Jython scripts for processing. On the Jython side, I have no trouble indexing into the object, i.e. baz = myFoo['bar'], but a lot of the standard dictionary methods aren't available. I'd like to be able to do this:

for k, v in myFoo.items(): # myFoo is from the Java side
  if (k == 'bar')

Specifically, I'd like to be able to use non-modifying dictionary methods, like items(), iteritems(), iterkeys(), itervalues(). How do I get there from here? I'm fine with an 80/20 solution; PyDictionary looks like what I need, except that I do not want the objects stored in the dict to inherit from PyObject (as a rule, the objects I'm storing do have nice Jython conversions). So, I want the class to look like a PyDictionary to the greatest extent possible, but to have its own implementation (which is complex and can't be swapped out).

As an aside, what's the difference between PyDictionary and PyDictionaryDerived?

Thanks in advance. I've been amazed with how easy it's been to get Jython embedding up and running; it's a huge win for my application.


Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
Jython-users mailing list

Santosh Tiwari