Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clone Collection in Java

Clone Collection in Java

Java のコレクションをクローンする場合のメモです。

Environment

  • Java 1.8
  • Apache Commons Lang 3.9

List

Collections.unmodifiableList(
    original.stream().map(SerializationUtils::clone).collect(Collectors.toList()));

Map

Collections.unmodifiableMap(
    original.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment