消费型接口
public class TestFunctional1 {
public static void main(String[] args) {
List<Integer > list = new ArrayList<>();
Collections.addAll(list,34,56,89,65,87);
//使用匿名内部类实现
Consumer consumer = new Consumer<Integer>() {
@Override
public void accept(Integer elem) {
System.out.println(elem);
}
};
list.forEach(consumer);
//使用Lambda表达式
//list.forEach((elem)->{System.out.println(elem);});
list.forEach((elem)->System.out.println(elem));
}
}