Java Lambda Collection/List篇
Java Lambda Collection/List篇  前言  這篇文章主要接續Lambda基礎篇,主要介紹與自我複習常用的Collection家族中的Lambda方法  Collection  forEach  forEach 是Iterable介面中的default Method原始碼如下  default void forEach(Consumer<? super T> action) {         Objects.requireNonNull(action);         for (T t : this) {             action.accept(t);         }     }  敲黑板 畫重點   Collection透過FunctionalInterface "Consumer"讓此介面可以透過lambda實踐。  Collection家族都有實作Iterable介面因此都可以使用此forEach方法。   實踐      private void forExample(List<String> example) {         example.forEach(System.out::println);     }  透過ArrayList實踐   System.out::println省列了不帶任何參數的method ()->,讓Lambda自動對物件使用此method   removeIf  removeIf是Collection介面本身的方法,原始碼如下      default boolean removeIf(Predicate<? super E> filter) {              Objects.requireNonNull(filter);         boolean removed = false;         final Iterator<E> each = iterator();         while (each.hasNext()) {             if (filter.test(each.next())) {                 each.remove();     ...