用lambda表达式求数组元素的最大值

Question:使用Supplier接口作为方法参数类型,通过lambda表达式求出int数组中的最大数

public class DemoTest{public ststic int getmax(Supplier <Integer> sup){return sup.get();}public ststic void main(String [] args){int [] arr=new [5];int value=getmax(()->{int max=arr[0];for(int i:arr){if(max<arr[i]){max=arr[i];}}return max;});System.out.println("数组中元素的最大值是"+value);}
}

在这里插入图片描述