Viki Jain
Viki Jain

Reputation: 127

How to write system.out.println as a method reference?

I am iterating a Collection using foreach, I am using intelliJ IDE.

queue.forEach(s->{
            System.out.println(s);
        });

I am getting warning here that "Can be replaced with method reference.."

can anyone suggest how can I use method reference here?

Upvotes: 4

Views: 9104

Answers (1)

pvpkiran
pvpkiran

Reputation: 27018

System.out::println

This should do

queue.forEach(System.out::println);

Upvotes: 8

Related Questions