fork(1) 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. String[] a = {"a","b","c","d"};
  14. String[] b = {"b", "c", "e"};
  15.  
  16. //this is to avoid calling Arrays.asList multiple times
  17. List<String> aL = Arrays.asList(a);
  18. List<String> bL = Arrays.asList(b);
  19.  
  20. //finding the common element for both
  21. Set<String> common = new HashSet<>(aL);
  22. common.retainAll(bL);
  23. System.out.println("Common: " + common);
  24.  
  25. //now, the real uncommon elements
  26. Set<String> uncommon = new HashSet<>(aL);
  27. uncommon.addAll(bL);
  28. uncommon.removeAll(common);
  29. System.out.println("Uncommon: " + uncommon);
  30. }
  31. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
Common: [b, c]
Uncommon: [d, e, a]