Skip to content

lambda expression

Keyhan Hadjari edited this page Sep 16, 2016 · 3 revisions
//Interface has to have only one method
public interface DOperation {
    int doIt(int[] a);
}

private int findByOperation(String[] input, DOperation operation) {
    return operation.doIt(input);
}
public void main(String[] args) {
    int[] input = new int[]{4,16,32,33};
    int result =  findByOperation(input, a -> Arrays.stream(a).max().getAsInt());
    System.out.println(result);// prints 33
}

Clone this wiki locally