Skip to content

Instantly share code, notes, and snippets.

@yavuztas
Last active August 27, 2019 15:30
Show Gist options
  • Save yavuztas/eadfab4de65ade413615689f78d9d85d to your computer and use it in GitHub Desktop.
Save yavuztas/eadfab4de65ade413615689f78d9d85d to your computer and use it in GitHub Desktop.
Created with Copy to Gist
public static <T> List<T> toList(Collection<T> collection) {
return collection.stream().collect(Collectors.toList());
}
public static <T> Set<T> toSet(Collection<T> collection) {
return UtilsForCollections.toSet(collection, false);
}
public static <T> Set<T> toSet(Collection<T> collection, boolean preserveOrder) {
if (preserveOrder) {
return collection.stream()
.collect(Collectors.toCollection(LinkedHashSet::new));
}
return collection.stream().collect(Collectors.toSet());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment