Dave's Brain

Browse - Programming Tips - How do I iterate through all keys/values of a HashMap in Scala?

Date: 2013may27
Language: Scala
Keywords: enumerate

Q.  How do I iterate through all keys/values of a HashMap in Scala?

A.  Use asScalaSet() like this:

import collection.JavaConversions._ val h = getJavaHashMapFromSomeWhere() for (e <- asScalaSet(h.entrySet())) { System.out.println(e.getKey() + " = " + e.getValue()) }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.