Open In App

IntStream boxed() in Java

Last Updated : 06 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

IntStream boxed() returns a Stream consisting of the elements of this stream, each boxed to an Integer.

Note : IntStream boxed() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :

Stream<Integer> boxed()

Parameters :

  1. Stream : A sequence of elements supporting sequential and parallel aggregate operations.
  2. Integer : The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

Return Value : The function returns a Stream boxed to an Integer.

Example 1 :




// Java code for IntStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream
        IntStream stream = IntStream.range(3, 8);
  
        // Creating a Stream of Integers
        // Using IntStream boxed() to return
        // a Stream consisting of the elements
        // of this stream, each boxed to an Integer.
        Stream<Integer> stream1 = stream.boxed();
  
        // Displaying the elements
        stream1.forEach(System.out::println);
    }
}


Output :

3
4
5
6
7

Example 2 :




// Java code for IntStream boxed()
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
  
class GFG {
  
    // Driver code
    public static void main(String[] args)
    {
        // Creating an IntStream
        IntStream stream = IntStream.range(3, 8);
  
        // Creating a Stream of Integers
        // Using IntStream boxed() to return
        // a Stream consisting of the elements
        // of this stream, each boxed to an Integer.
        Stream<Integer> stream1 = stream.boxed();
  
        Stream<Object> stream2 = Stream.concat(stream1,
                                    Stream.of("Geeks", "for", "Geeks"));
  
        // Displaying the elements
        stream2.forEach(System.out::println);
    }
}


Output :

3
4
5
6
7
Geeks
for
Geeks


Similar Reads

LongStream boxed() in Java
LongStream boxed() returns a Stream consisting of the elements of this stream, each boxed to a Long. Note : LongStream boxed() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output. Syntax : Stream&lt;Long
2 min read
DoubleStream boxed() in Java with Examples
DoubleStream boxed() returns a Stream consisting of the elements of this stream, each boxed to a Double. Note : DoubleStream boxed() is a intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output. Syntax : Stream
2 min read
IntStream iterator() in Java
IntStream iterator() returns an iterator for the elements of this stream. It is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. Syntax : PrimitiveIterator.OfInt iterator() Where, PrimitiveIterator.OfInt is an Iterator specialized for int values. Return Value : IntStream iterator() returns the element itera
2 min read
IntStream rangeClosed() in Java
IntStream rangeClosed(int startInclusive, int endInclusive) returns an IntStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1. Syntax : static IntStream rangeClosed(int startInclusive, int endInclusive) Parameters : IntStream : A sequence of primitive int-valued elements. startInclusive : The inclusive ini
1 min read
IntStream map(IntUnaryOperator mapper) in Java
IntStream map(IntUnaryOperator mapper) returns a stream consisting of the results of applying the given function to the elements of this stream. This is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
2 min read
IntStream findFirst() in Java
IntStream findFirst() returns an OptionalInt (a container object which may or may not contain a non-null value) describing the first element of this stream, or an empty OptionalInt if the stream is empty Syntax : OptionalInt findFirst() Where, OptionalInt is a container object which may or may not contain a non-null value and the function returns a
2 min read
IntStream parallel() in Java
IntStream parallel() is a method in java.util.stream.IntStream. This method returns a parallel IntStream, i.e, it may return itself, either because the stream was already present, or because the underlying stream state was modified to be parallel. IntStream parallel() is an intermediate operation. These operations are always lazy. Intermediate oper
2 min read
IntStream empty() in Java with examples
IntStream empty() is a method in java.util.stream.IntStream. This method returns an empty sequential IntStream. Syntax : static &lt;T&gt; Stream&lt;T&gt; empty() Where, T is the type of stream elements, and the function returns an empty sequential stream. Example 1 : Creating empty IntStream. // Java code for IntStream empty() import java.util.*; i
1 min read
IntStream distinct() in Java with examples
IntStream distinct() is a method in java.util.stream.IntStream. This method returns a stream consisting of the distinct elements. This is a stateful intermediate operation i.e, it may incorporate state from previously seen elements when processing new elements. Syntax : IntStream distinct() Where, IntStream is a sequence of primitive int-valued ele
2 min read
IntStream peek() in Java with examples
IntStream peek() is a method in java.util.stream.IntStream. The function returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. Syntax : IntStream peek(IntConsumer action) Where, IntStream is a sequence of primitive int-valued elemen
3 min read
Article Tags :
Practice Tags :