title: Returning generic arrays in Java
body: <p>I am having problems at the moment of initialize the array and returning it. The method is suppose to return common items of a generic array, but i cant initialize array "a" or returning it. Any advice?? </p>
  
  <pre><code>public static &lt;T&gt; T[] commonItems( T[] arr1, T[] arr2)
  {
      T[] a;
      int pos = 0;
      for( int i = 0; i &lt; arr1.length; i++)
      {
          for(int j = 0; j &lt; arr2.length; j++)
          {
             if(arr1[i].equals(arr2[j]))
             {
                 a[pos] = arr1[i];
                 pos++;
             }
          }
      }
      return a;
  }
  </code></pre>