title: Converting List<String> to String[] in Java
body: <p>How do I convert a <a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html" rel="noreferrer">list</a> of String into an <a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html" rel="noreferrer">array</a>? The following code returns an error.</p>
  
  <pre><code>public static void main(String[] args) {
      List&lt;String&gt; strlist = new ArrayList&lt;String&gt;();
      strlist.add("sdfs1");
      strlist.add("sdfs2");
      String[] strarray = (String[]) strlist.toArray();       
      System.out.println(strarray);
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
      at test.main(test.java:10)
  </code></pre>