title: Java - Finding unique elements in two different arrays
body: <p>I need to find the unique elements in two different arrays. </p>
  
  <pre><code>public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          int[] arr1 = new int[] { 1, 2, 3, 4, 5, 6 };
          int[] arr2 = new int[] { 5, 6, 7, 8 };
  
          boolean contains = false;
          List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
          for (int i = 0; i &lt; arr1.length; i++) {
              for (int j = 0; j &lt; arr2.length; j++) {
                  if (arr1[i] == arr2[j]) {
                      contains = true;
                      break;
                  }
              }
  
              if(!contains){
                  list.add(arr1[i]);
              }
              else{
                  contains = false;
              }
          }
          System.out.println(list);
  
      }
  </code></pre>
  
  <p>But here I'm getting <code>[1,2,3,4]</code> as output. But the expected output is <code>[1,2,3,4,7,8]</code>. I'm not sure what I'm doing wrong here. And I need it in a traditional way. I don't want to use any inbuilt methods to acheive this.</p>
  
  <p>Note: I feel it is not a duplicate because, the solution provided is not finding the unique elements on two arrays.</p>