Java interoperability
As we mentioned earlier, Scala has very rich collection API. The same applies for but there are lots of differences between the two collection APIs. For example, both APIs have iterable, iterators, maps, sets, and sequences. But Scala has advantages; it pays more attention to immutable collections and provides more operations for you in order to produce another collection. Sometimes, you want to use or access Java collections or vice versa.
Note
JavaConversions
is no longer a sound choice. JavaConverters
makes the conversion between Scala and Java collection explicit and you'll be much less likely to experience implicit conversions you didn't intend to use.
As a matter of fact, it's quite trivial to do so because Scala offers in an implicit way to convert between both APIs in the JavaConversion
object. So, you might find bidirectional conversions for the following types:
Iterator <=> java.util.Iterator Iterator <=> java.util...