Supplier接口练习之获取最大值
public class SupplierTest { public static void main(String[] args) { //定义数组 int[] a = {10,20,33,12,99}; //调用方法获取最大值 int MaxValue = getMax(()->{ int Max = a[0]; for (int i = 1; i<a.length;i++){ if (a[i] > Max){ Max = a[i]; } } return Max; }); System.out.println("最大值是:"+MaxValue); } private static int getMax(Supplier<Integer> sup){ return sup.get(); } }
学习的博客多用于在笔记中,防止笔记过于臃肿,所以将样例及运行结果放在博客中,后以超链接的形式记录在笔记中,所以有些博文过于单薄。如果有小伙伴遇到问题欢迎评论,看到就会回复,学渣一枚,加油努力。