package org.onepiece;
import java.lang.String;
import java.util.*;
import java.util.stream.Stream;
public class Main {
/**
* 创建流
*/
public static void main(String[] args) {
//Stream.of 可变参数
Stream stream1 = Stream.of(1, 2, 3);
//stream1.forEach(System.out::println);
stream1.forEach(x -> System.out.print(x + " ")); //1 2 3
println("");
//Stream.of 数组
Integer[] intArray = {4, 5, 6};
Stream stream2 = Stream.of(intArray);
stream2.forEach(x -> System.out.print(x + " ")); //4 5 6
println("");
//Arrays.stream
Stream stream3 = Arrays.stream(intArray);
stream3.forEach(x -> System.out.print(x + " ")); //4 5 6
println("");
//List.stream
List<Integer> intList = new ArrayList<>(Arrays.asList(7, 8, 9));
Stream stream4 = intList.stream();
stream4.forEach(x -> System.out.print(x + " ")); //7 8 9
println("");
Stream stream5 = Arrays.asList(10, 11, 12).stream();
stream5.forEach(x -> System.out.print(x + " ")); //10 11 12
println("");
//Set.stream
Set<Integer> set = new HashSet<>(Arrays.asList(1, 3, 5));
Stream stream6 = set.stream();
stream6.forEach(x -> System.out.print(x + " ")); //1 3 5
println("");
//Map
Map<Integer, String> map = new HashMap<>();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
Stream<String> stream7 = map.values().stream();
stream7.forEach(x -> System.out.print(x + " ")); //one two three
println("");
}
private static void println(Object obj) {
System.out.println(obj);
}
}