Streams work on Collections of non-primitive data types for example Integer, String, Long, Double, etc but Java provides a way to work on primitive data types using IntStream, LongStream and DoubleStream, so convert a stream of primitives, you should first box the elements in their wrapper class and then collect them. This type of stream is called boxed stream.

Example:

package com.javatutsworld.stream;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Java8MapofList {

    public static void main(String... args) {
        // IntStream
        IntStream intStrm = IntStream.of(1, 2, 3, 4, 5);
        Stream<Integer> streamboxed = intStrm.boxed();
        System.out.println("IntStream Output");
        streamboxed.forEach(System.out::println);

        // Creating an IntStream and use concat mathod
        IntStream str = IntStream.range(3, 5);
        Stream<Integer> streamboxed1 = str.boxed();
        Stream<Object> streamConcat = Stream.concat(streamboxed1,
                Stream.of("Mukarram", "Ali"));


        System.out.println("IntStream Output after concat: ");
        streamConcat.forEach(System.out::println);

        // LongStream
        List<Long> longStrm = LongStream.of(1l, 2l, 3l, 4l, 5l).boxed()
                .collect(Collectors.toList());
        System.out.println("LongStream Output");
        System.out.println(longStrm);

        // DoubleStream
        List<Double> doubleStrm = DoubleStream.of(1d, 2d, 3d, 4d, 5d).boxed()
                .collect(Collectors.toList());
        System.out.println("DoubleStream Output");
        System.out.println(doubleStrm);
    }
}

Output:

IntStream Output
1
2
3
4
5
IntStream Output after concat: 
3
4
Mukarram
Ali
LongStream Output
[1, 2, 3, 4, 5]
DoubleStream Output
[1.0, 2.0, 3.0, 4.0, 5.0]

Difference Between Collections And Streams In Java

Collection is a data structure which is used to store the data let say we have a group of AccountDetails and we can store these AccountDetails to collection's list. A finite number of elements can be stored, add or remove elements from collections. Collection API constructs objects in an eager manner. Collections can be traversed multiple times.

Stream does not store data and used to perform operations on that data structure we can not add to or remove elements from streams. Stream API creates objects in a lazy manner. Streams are traversable only once.