I’m trying to convert below Java code to Scala:
Map<String, List<String>> allEntriesMap = getEntries();
for (Map.Entry<String, List<String>> allEntriesMapEntry : allEntriesMap
.entrySet()) {
}
Here is the current Scala version of above Java code:
var allEntriesMap : Map[String, List[String]] = getEntries();
for (allEntriesMap.entrySet[String, List[String]] allEntriesMapEntry :
allEntriesMap.entrySet()) {
}
I’m receiving this error for line
for (allEntriesMap.entrySet[String, List[String]] allEntriesMapEntry :
illegal start of simple pattern
How can above code be finished so that it performs same Java functionality but written in Scala?
The problem is that you use incorrect syntax. This
Should be written as:
or simply
Moreover, if you’re using java collections type you have to import
scala.collections.JavaConversions._into scope (that will implicitly convert java collections into scala ones, so you may use all set of operations on them).