'What is ' :: ' double colon in Java? When should I use it? [duplicate]

I'm just a beginner in Java. When should I use double colon?

import java.util.stream.*;

class GFG {

    public static void main(String[] args)
        // Get the stream
        Stream<String> stream= Stream.of("Geeks", "For", "Geeks", "A", "Computer", "Portal");

        // Print the stream
        // using double colon operator

Solution 1:[1]

The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions. The only difference it has from lambda expressions is that this uses direct reference to the method by name instead of providing a delegate to the method.



This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Spectric