Last active
June 26, 2018 15:09
-
-
Save coltin/19b3689c2b387f19661e4238deaa6b68 to your computer and use it in GitHub Desktop.
A nice interface to concatenating multiple lists in java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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