In the scala.collection.jcl
library, you'll find Scala wrappers, adding Scala methods to Java collections. This means that a Java collection (e.g., an ArrayList
) will be converted to work as a Scala collection, making it possible to call foreach on a ArrayList
, etc:
import scala.collection.jcl.Conversions._Simlarily, you can now call
val a = new java.util.ArrayList[String]
a.add("Asa")
a.add("nisi")
a.add("masa")
// foreach now works on a Java List:
a.foreach(println)
.mkString
on a Java list: // Let's use mkString to print the
// ListArray contents as a Prolog spell/3 fact:
println(a.mkString("spell('", "', '", "')."))
// -> spell('Asa', 'nisi', 'masa').
See this Scala mailing list thread.
No comments:
Post a Comment