KKO
KKO

Reputation: 1933

Java's "forEach" to Scala

How can the following be converted to scala? If I live it as it is, I'm getting a big type mismatch expected

.entrySet().forEach(entry -> {..})

I tried specifying entry to java.util.Map.Entry, or changing to scala foreach, doesn't work.

Let me know if you need any more info/code, and I'll create some dummy example since I'm not allowed to post the exact code.

Upvotes: 4

Views: 3505

Answers (2)

Govind Singh
Govind Singh

Reputation: 15490

check this

Iterating over Java collections in Scala

for each in scala

for(entry<-entrySet){
//
}

or

entrySet.foreach{entry=>
//
}

or

.entrySet.map{entry => 
//
}

Upvotes: 3

gun
gun

Reputation: 1066

Just

import scala.collection.JavaConversions._

for an implicit conversion to scala collections.

Upvotes: 1

Related Questions