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. int [] a = {1,2,3,4,5,6,7}; // arranjo 1
  13. int [] b = {0,1,2,3}; // arranjo 2
  14. String intersec = "";
  15.  
  16. for(int i = 0; i < a.length; i++) {
  17. for(int y = 0; y < b.length; y++){
  18. if(a[i] == b[y])
  19. intersec += a[i] + ";";
  20. }
  21. }
  22.  
  23. String[] intersecao = intersec.split(";");
  24.  
  25. System.out.println(Arrays.asList(intersecao));
  26.  
  27. }
  28. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
[1, 2, 3]