2

I have a written a method in Scala that is using a method written in Java - processSale() method takes util.List<Sale> as a parameter.

But after groupByKey() I'm getting an RDD[(String, Iterable[Sale])]. I've tried to import scala.collection.JavaConverters._ and do SaleParser.processSale(a.asJava).

However it gives me an Iterable[Sale]. How is it possible to convert it into a Java util.List?

val parseSales: RDD[(String, Sale)] = rawSales
      .map(sale => sale.Id -> sale)
      .groupByKey()
      .mapValues(a => SaleParser.processSale(???))

1 Answer 1

3
a.toSeq.asJava

Note that if this Iterable is actually a Seq, toSeq just returns the same object.

See API doc for the complete list of conversions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.