Convert java.util.Map to Scala List[NewObject] -


i have java.util.map[string, myobject] , want create scala list[mynewobject] consisting of alle entries of map special values.

i found way but, well, ugly:

val result = listbuffer[mynewobject]() myjavautilmap.foreach   (    (es: entry[string, myobject]) =>        { result += mynewobject(es.getkey(), ey.getvalue().getmyparameter); println("aa")}   ) 

how can rid of println("aa")? deleting not because foreach needs consumer += operation yields list....

is there more elegant way convert java.util.map list[mynewobject]?

scala has conversions give nice methods of scala collection api on java collections:

import collection.javaconversions._ val result = myjavautilmap.map{   case (k,v) => mynewobject(k, v.getmyparameter) }.tolist 

by way: define function returns unit, can explicitly specify return type:

val f = (x: int)  => x: unit 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -