Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Array[String] to Java Collection[String]

Tags:

scala

I have a Scala array of strings:

val names:Array[String] = something.map(...)

I need to call an Android(java) method that accepts a Collection

public void addAll (Collection<? extends T> collection)

How do I covert the Array to a Collection?

like image 649
Steve Avatar asked Jan 11 '12 15:01

Steve


1 Answers

JavaConversions is now deprecated. You should use JavaConverters instead.

import collection.JavaConverters.asJavaCollection
val collection = asJavaCollection(Array("some value"))
like image 133
RubberDuck Avatar answered Sep 27 '22 17:09

RubberDuck