Create Comparator via method reference - Java Lambda Stream

Java examples for Lambda Stream:Method Reference

Description

Create Comparator via method reference

Demo Code

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Main {

  public static void main(String[] args) {
    List<String> list = Arrays.asList("1", "4", "2");

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

    Comparator<String> t = Comparator.comparing(String::length);

  }/*  w  ww .jav  a  2 s . c  o m*/
}

Related Tutorials