Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Consumer<List<Integer>> methodRef = Collections::sort;

I am trying to write the code around this syntax.

public static void main(String[] args) {

Consumer<List<Integer>> methodRef = Collections::sort;

        List<Integer> al = new ArrayList<>();
        al.add(1);
        al.add(4);

       methodRef.accept(al);
       System.out.println(methodRef);
}

the output is :
methodreferences.MethodReferenceTest$$Lambda$14/0x0000000800c01200@119d7047

please help me get the correct output.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I expect to see the list of sorted values method reference way.

>Solution :

Collections#sort sorts its input list.
System.out.println(al); to output the (now sorted) list.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading