Skip to content

Instantly share code, notes, and snippets.

@jon-ruckwood
Created August 5, 2015 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-ruckwood/42f75901bc7329ccab47 to your computer and use it in GitHub Desktop.
Save jon-ruckwood/42f75901bc7329ccab47 to your computer and use it in GitHub Desktop.
Java 8 Collector for a Guava ImmutableList
public final class ImmutableListCollector {
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() {
return Collector.of(
ImmutableList::builder,
ImmutableList.Builder::add,
(left, right) -> { left.addAll(right.build()); return left; },
ImmutableList.Builder::build);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment