Java string array to stream

w‮al.ww‬utturi.com
Java string array to stream

To convert a Java string array to a stream, you can use the Arrays.stream method and pass the string array as an argument. Here's an example:

String[] stringArray = {"a", "b", "c"};
Stream<String> stream = Arrays.stream(stringArray);

You can then use the various methods on the Stream object to perform operations on the elements of the string array. For example, you can use the map method to apply a function to each element of the stream, or use the filter method to select only certain elements.

Here's an example of using the map method to convert each string in the stream to uppercase:

Stream<String> uppercaseStream = stream.map(String::toUpperCase);

And here's an example of using the filter method to select only strings that contain the letter "a":

Stream<String> filteredStream = stream.filter(s -> s.contains("a"));

You can find more information about the Stream interface and the various methods it provides in the Java documentation.

Created Time:2017-10-17 20:18:52  Author:lautturi