fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. List<String> list1 = new ArrayList<>(List.of("c", "e"));
  14. List<String> list2 = new ArrayList<>(List.of("c", "e", "f"));
  15.  
  16. List<String> intersection = new ArrayList<>(list1);
  17. intersection.removeAll(list2);
  18.  
  19. System.out.println("List1: " + list1);
  20. System.out.println("List2: " + list2);
  21. System.out.println("差分: " + intersection); // 出力: [c, e]
  22. }
  23. }
Success #stdin #stdout 0.12s 57480KB
stdin
Standard input is empty
stdout
List1: [c, e]
List2: [c, e, f]
差分: []