Search code examples
javaarraylistremoveall

loop through and compare 2 array lists and find a match


I have 2 array lists. I want to return the unique value between the two. How is this done?

String[] s1 = {10, 1};
String[] s2 = {10, 1, 13};

//loop through and compare element of s1 to s2     
//switch varialbe used to indicate whether a match was found
boolean matchFound = false;

//outer loop for all the elements in s2
for (int i = 0; i < s2.lenght; i++) {
  //inner loop for all the elements in s1
  for (int i = 0; i < s1.lenght; i++) {
     matchFound = true;
     System.out.println("This " + s2[i] + "was found");
  }
}
if(matchFound == false) {
  System.out.println("This " + s2[i] + "was not found");
}
//set matchFound bool back to false
matchFound = false;
}

Solution

  • I updated my question with the correct answer.