Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

Alexey CheFeb 4 2019 — edited Feb 4 2019

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 -version

javac 11.0.1

java -version

java version "11.0.1" 2018-10-16 LTS

Java(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.

Comments

Post Details

Added on Feb 4 2019
0 comments
99 views