In Java 8 - Find all even numbers between 1 to 5











Program/ Example -
       //In Java 8 - Find all even numbers between 1 to 5
       //Use streams
       System.out.println("--");
       IntStream.range(1, 6)  //Numbers between 1 to 5
        .filter(n -> n % 2 == 0) //Filter - all even numbers
        .forEach(System.out::println); //display
       //or
       System.out.println("--");
          IntStream.of(1, 2, 3, 4, 5)  //Numbers between 1 to 5
        .filter(n -> n % 2 == 0) //Filter - all even numbers
        .forEach(System.out::println); //display
       


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.





eEdit
Must read for you :