ListUtils { public static <T> Collector<T, ?, ImmutableList<T>> toImmutableList() { return Collector.<T, List<T>, ImmutableList<T>>of( ArrayList::new, List::add, (left, right) -> { left.addAll(right); return left; }, ImmutableList::copyOf ); } private  ListUtils(); static int firstIndexOf(List<? extends T> list, Predicate<? super T> predicate); static boolean addIfNotPresent(List<? super T> list, T element); static boolean addIfNotPresent(List<? super T> list, int index, T element); static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, List<T>> joining(Supplier<? extends T> separator); static Collector<T, ?, List<T>> joining(Supplier<? extends T> prefix,
                                                     Supplier<? extends T> separator,
                                                     Supplier<? extends T> suffix); static Replacement<T> replaceIn(List<T> list);  }
@Test public void testToImmutableList() { List<String> list = Arrays.asList( foo, bar, "baz", bar, foo, "abcd" ); ImmutableList<String> immutableList = list.stream().collect(ListUtils.toImmutableList()); assertEquals(list, immutableList); }