arrays

How to convert a Java array into a Stream

If you ever need to convert a Java array into a Stream, there are at least two ways to do it.

1) Converting an array to a Stream

First, to convert the entire array to a Stream, use the Stream.of static method like this:

How to pass Scala arrays back and forth with Java methods

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 11.12, “How to Pass Arrays Back and Forth with Java Methods”

Problem

You want to pass an array back and forth between your Scala and Java methods.

How to sort Arrays in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is one of the shortest recipes in the book, Recipe 11.10, “How to Sort Arrays in Scala”

Problem

You want to sort the elements in an Array (or ArrayBuffer).

Passing arrays back and forth between Scala and Java

Scala FAQ: How can I pass an array back and forth between Scala and Java code?

Solution

The first link in the See Also section states, “Scala arrays correspond one-to-one to Java arrays,” and as a result of this, passing arrays back and forth between Java and Scala code is easier than the example shown in Recipe 17.1 in the Scala Cookbook, “Going to and from Java Collections.”

Java array sorting: How to sort a Java String array

Java array FAQ: Can you share an example of how to sort a Java String array?

Sure. The following source code shows how to sort an array of strings. In short, you can easily sort a string array with the Arrays class sort method, shown in bold below: