//TestIntStreamWithCollectors.java

import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class TestIntStreamWithCollectors
{
    public static void main(String[] args)
    {
        //Prints the values one per line ...
        IntStream
        .range(1, 10)
        .forEach(System.out::println);

        //But what if you want them all on one line?
        System.out.println
        (
            IntStream
            .range(1, 10)
            .boxed() //Converts the int values to Integer
            .map(i -> i.toString())
            .collect(Collectors.joining(" "))
        );

        //Note the "closed" range and the additional
        //intermediate filter() operation ...
        System.out.println
        (
            IntStream
            .rangeClosed(1, 100)
            .filter(i -> i / 10 + i % 10 > 12)
            .boxed()
            .map(i -> i.toString())
            .collect(Collectors.joining(" "))
        );
    }
}
/*  Output:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    1 2 3 4 5 6 7 8 9
    49 58 59 67 68 69 76 77 78 79 85 86 87 88 89 94 95 96 97 98 99
*/
