测试下java函数式编程的几个接口
//看着很简洁,就是有点难理解 public class Iterator_test { public static void main(String[] args) { List<String> list=new ArrayList<>(); list.add("343"); list.add("343434"); //使用Consumer接口 //函数式编程,消费者 list.forEach((String s)-> {System.out.println(s);}); list.forEach(s->System.out.println(s)); list.forEach(System.out::println); //使用Function接口 String s=Function_test("hello word",(s1)->s1+" wind"); String s2=Function_test("hello word",(s1)->{String a=s1+" hi";return a;}); System.out.println(s); System.out.println(s2); //测试supplier接口 List<Integer> mao=Supplier_test(5,()->(int)(Math.random()*10)); mao.forEach