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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java approach:
Scala approach:
In the latter approach
namesarray is first converted toSeq[String]and then an implicit conversion located inJavaConversionsfigures out that Java collection is needed so it applies necessary transformation trasparently. Don’t worry, it is constant in time.