Forum Stats

  • 3,838,712 Users
  • 2,262,395 Discussions
  • 7,900,739 Comments

Discussions

Why a lambda expression inside the map method don't working, when terminal operation is the count an

Alexey Che
Alexey Che Member Posts: 1
edited Feb 4, 2019 9:55AM in Java Programming

Good day.

I don't understand why a lambda expression inside the map method don't working, when terminal operation is the count and a stream was generated from an ArrayList?

Here is a simplified snippet:

        java.util.List<Integer> data = new ArrayList<>();        for(int i = 0; i < 4000; i++) {            data.add(i);        }        data.stream().map(a -> {            System.out.println(a);//NEWER CALLED            return a+1;}).count();

I am on Windows 10, my java version is:

javac -versionjavac 11.0.1java -versionjava version "11.0.1" 2018-10-16 LTSJava(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Regards,

Alexey.