Skip to content

Instantly share code, notes, and snippets.

@coltin
Last active June 26, 2018 15:09
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 coltin/19b3689c2b387f19661e4238deaa6b68 to your computer and use it in GitHub Desktop.
Save coltin/19b3689c2b387f19661e4238deaa6b68 to your computer and use it in GitHub Desktop.
A nice interface to concatenating multiple lists in java.
@SafeVarargs
public static <T> List<T> concat(List<T>... lists) {
return Stream.of(lists)
.reduce(
new ArrayList<T>(),
(resultList, currentList) -> {
resultList.addAll(currentList);
return resultList;
});
}
// Example if you have list1, list2, list3:
// List<T> someNewHybridList = concat(list1, list2, list3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment