The boxed() method in Java Stream is used to wrap the primitive value (int, long or double) to its respective wrapper class object. There are primitive specializations of Stream named IntStream, LongStream and DoubleStream each of these interfaces have a boxed() method that returns a Stream consisting of the elements of this stream, each boxed to an Integer, Long or Double respectively. Note that boxed() is an intermediate operation . boxed stream Java examples Let’s see few examples how to box a primitive value into its wrapper class using boxed() method. 1. boxed() in IntStream which is used to get a Stream consisting of the elements of this stream, each boxed to an Integer. import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; public class BoxedIntStream { public static void main(String[] args) { Stream<Integer> wrappedInts = IntStream.of(1, 2, 3, 4, 5).boxed(); List<Integer>
Java, Spring, Web development tutorials with examples