Search code examples
javamvel

How to iterate over a map in mvel


I have a collection (map) which I want to use with the foreach orb tag.

How do i do this in mvel and is it also possible to get the current key?


Solution

  • Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    
    //java
    for (Map.Entry<Integer, Integer> entry : map.entrySet()) 
    {
        System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
    }
    
    //mvel
    foreach (c : map.entrySet) 
    {
    
       System.out.println("Key = " +c.key + ", Value = " +c.value);
    }