Skip to content

Instantly share code, notes, and snippets.

@takashima0411
Created June 2, 2015 07:34
Show Gist options
  • Save takashima0411/35c68cb9c2fee9437955 to your computer and use it in GitHub Desktop.
Save takashima0411/35c68cb9c2fee9437955 to your computer and use it in GitHub Desktop.
Javaで2つのリストの差をとる
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) throws Exception {
List<Integer> before = Arrays.asList(1,2,3,4,5);
List<Integer> after = Arrays.asList(1,4,5,6);
System.out.print("removed:");
System.out.println(before.stream().filter(e -> !after.contains(e)).map(Object::toString).collect(Collectors.joining(",")));
System.out.print("added:");
System.out.println(after.stream().filter(e -> !before.contains(e)).map(Object::toString).collect(Collectors.joining(",")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment