int[] buf={1,2,3,4,5,6,7};
IntStream stream = Arrays.stream(buf);
Stream<int[]> buf1 = Stream.of(buf);
List<String> list =new ArrayList();
Stream<String> stream1 = list.stream();
Stream<List<String>> list1 = Stream.of(list);
Stream<String> stringStream = list.parallelStream();
BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("/abc")));
Stream<String> lines = bufferedReader.lines();
IntStream range = IntStream.range(2, 30);
Path path = Paths.get("/abc");
Stream<Path> walk = Files.walk(path);
IntStream.of(new int[]{1, 2, 3}).forEach(System.out::println);
IntStream.range(1, 3).forEach(System.out::println);
IntStream.rangeClosed(1, 3).forEach(System.out::println);
// 1. Array
String[] strArray1 = stream.toArray(String[]::new);
// 2. Collection
List<String> list1 = stream.collect(Collectors.toList());
List<String> list2 = stream.collect(Collectors.toCollection(ArrayList::new));
Set set1 = stream.collect(Collectors.toSet());
Stack stack1 = stream.collect(Collectors.toCollection(Stack::new));
// 3. String
String str = stream.collect(Collectors.joining()).toString();
List<String> wordList=new ArrayList<>();
wordList.add("a");
wordList.add("b");
wordList.add("c");
List<String> collect = wordList.stream().
map(String::toUpperCase).
collect(Collectors.toList());
//平方
List<Integer> nums = Arrays.asList(1, 2, 3, 4);
List<Integer> squareNums = nums.stream().
map(n -> n * n).
collect(Collectors.toList());
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |