Stream to Array - Java-8

1. Stream to String[]

In Java 8, we can use .toArray() to convert a Stream into an Array.

package com.geekscoder;

import java.util.Arrays;

public class StreamToStringArray {

    public static void main(String[] args) {

        String string = "Geeks Coder";
        String[] result = Arrays.stream(string.split("\\s+")).map(String::toUpperCase).toArray(String[]::new);

        for (String s : result) {
            System.out.println(s);
        }

    }

}
Output
Geeks
Coder