title: generic method to print all elements in an array
body: <p>I wanna a method that would loop any type array and print them, I have written the following:</p>
  
  <pre><code>public static &lt;T&gt; void printArray(T[] arr){
      for(T t: arr){
         System.out.print(t+" ");
      }
      System.out.println("");
  }
  </code></pre>
  
  <p>but this one only works for class arrays, what if I have a <code>char[]</code> instead of a <code>Character[]</code>, or a <code>int[]</code> instead of an <code>Integer[]</code>, or is there a way to cast them before hand? Thanks</p>