Although you have accepted an answer, I think it is better to add something as not to mislead other people:
... had a method to return array of keys (entrySet) which is not the case with me
First, Map is a Map. Map created in MVEL is simply a "Java" Map. The way to iterate is just the same and they are providing same methods
Second, entrySet()
is not returning "array of keys". It is returning a Set of Entry (as its name suggests).
I am not sure why you cannot use entrySet
as it works just fine for me. I suspect you have do foreach (e : map.entrySet)
. That will not work, because in MVEL, property navigation can mean several thing, like bean properties (which means it will call map.getEntrySet()
), or looking up a map (which means it will call map.get('entrySet')
), or getting the field (which means 'map.entrySet'). However all these are not valid for your case. You simply want to invoke map.entrySet()
method so that you should just do foreach (e : map.entrySet())
The proper way to do is something like this:
map = ['a':'a1', 'b':'b1'] ;
foreach(entry : map.entrySet()) {
System.out.println('key ' + entry.key + ' value ' + entry.value)
};