Scala Java Interoperability
Converting Scala Collections to Java Collections and vice versa
When you need to pass a collection into a Java method:
If the Java code returns a Java collection, you can turn it into a Scala collection in a similar manner:
Note that these are decorators, so they merely wrap the underlying collections in a Scala or Java collection interface. Therefore, the calls .asJava and .asScala do not copy the collections.
Arrays are regular JVM arrays with a twist that they are treated as invariant and have special constructors and implicit conversions. Construct them without the new keyword.
Now a has type Array[String].
Although String is convertible to CharSequence, Array[String] is not convertible to Array[CharSequence].
You can use an Array like other collections, thanks to an implicit conversion to TraversableLike ArrayOps:
Most of the Scala collections (TraversableOnce) have a toArray method taking an implicit ClassTag to construct the result array:
This makes it easy to use any TraversableOnce in your Scala code and then pass it to Java code which expects an array.