Thursday, September 11, 2014

Method Reference in Java 8

import java.util.ArrayList;
import java.util.List;

public class MethodReference {
       public static void main(String[] args) {
              List strings = new ArrayList<>();      
              strings.add("actor");
              strings.add("bat");
              strings.add("do");
              strings.add("i");         
              strings.sort(String::compareTo);
              strings.forEach(System.out::println);
       }
}

Output:

actor
bat
do
i


No comments:

Post a Comment