find if there exists a common element in 2 arrays
<p>Given two arrays of integers, how can you efficiently find out if the two arrays have an element in common?</p>

<p>Can somebody come up with a better space complexity than this (I would appreciate pointing errors in the program too, thanks!!).</p>

<p>Is it possible to solve this using a XOR?</p>

<pre><code>public boolean findcommon(int[] arr1, int[] arr2) {
  Set&lt;int&gt; s = new Hashset&lt;int&gt;();
  for(int i=0;i&lt;arr1.length;i++) {
    if(!s.contains(arr1[i]))
      s.add(arr1[i]);
  }
  for(int i=0;i&lt;arr2.length;i++) {
    if(s.contains(arr2[i]))
        return true;
  }
  return false;
}
</code></pre>
