Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 534
KKO Avatar asked Oct 18 '25 16:10

KKO


2 Answers

check this

Iterating over Java collections in Scala

for each in scala

for(entry<-entrySet){
//
}

or

entrySet.foreach{entry=>
//
}

or

.entrySet.map{entry => 
//
}
like image 189
Govind Singh Avatar answered Oct 21 '25 05:10

Govind Singh


Just

import scala.collection.JavaConversions._

for an implicit conversion to scala collections.

like image 33
gun Avatar answered Oct 21 '25 05:10

gun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!