Java 8 StreamBox Java 8 Boxed Streams

1. What is a Boxed Stream?

In Java8, if we want to turn an object flow into a collection, we can use one of the static methods in the Collectors class

List<String> strings = Stream.of("how", "to", "do", "in", "java")
                    .collect(Collectors.toList());

But for the basic type of missing data is not appropriate

IntStream of(1,2,3,4,5) //. Collect (Collectors.tolist ());

To avoid compilation errors, we must wrap the element and then collect the wrapped object in the collection. This type of stream is called a boxed stream

2.intStream intoIntegeR collection
List<Integer> ints = IntStream. Of (1,2,3,4,5).boxed(). Collect (Collectors.tolist ()); System.out.println(ints); Optional<Integer> Max = IntStream.of(1,2,3,4,5).boxed().max(Integer:: Compareto); System.out.println(max)
3. LongStream

Replace a long flow with a long

List<Long> longs = LongStream.of(1l,2l,3l,4l,5l)
                .boxed()
                .collect(Collectors.toList());

4. doubleStream
List<Double> doubles = DoubleStream.of(1d,2d,3d,4d,5d)
                .boxed()
                .collect(Collectors.toList());