Java 8流到数组


Java 8流到数组

import java.util.Arrays;

import java.util.List;

import java.util.stream.Collectors;

import java.util.stream.Stream;



public class J8StreamToArray {

   public static void main(String args[]) {

      String[] myArray = { "JavaFX", "OpenCV", "WebGL", "HBase" };

      Stream<String> stream = Stream.of(myArray);

      List<String> list = stream.collect(Collectors.toList());

      String[] str = list.toArray(new String[0]);

      System.out.println(Arrays.toString(str));

   }

}