title: In which condition which overloaded version of toArray() and toArray(T[] a) should be use?
body: <p>I never use overloaded version of toArray <code>Object[] toArray(Object[] a)</code> to convert collection into array.</p>
  
  <p>below is my javacode-</p>
  
  <pre><code>public class Track {
   public static void main(String x[]) {
       ArrayList&lt;String&gt; iName = new ArrayList&lt;String&gt;();
       iName.add("Arpit1");
       iName.add("Arpit2");
       iName.add("Dubey1");
       iName.add("Dubey2");
       Object[] array= iName.toArray();
  
       for(int i=0;i&lt;array.length;i++)
           System.out.println(array[i].getClass());
   }
   }
  </code></pre>
  
  <p>Output-</p>
  
  <blockquote>
    <p>class java.lang.String</p>
    
    <p>class java.lang.String</p>
    
    <p>class java.lang.String</p>
    
    <p>class java.lang.String</p>
  </blockquote>
  
  <p>Expected-</p>
  
  <blockquote>
    <p>class java.lang.Object</p>
  </blockquote>
  
  <p>there are some other question related this I go through all but no one pointing my query.</p>