title: Convert ArrayList to Array
body: <p>I'm having a little trouble converting an array list to an array in java. </p>
  
  <p>I have a class called Table which contains an array list called <code>applicants</code> which takes Strings. When I use my <code>toArray()</code> function it doesn't seem to convert the array list into an array.</p>
  
  <p>I know this because when i run the listArray() function it gives the error: </p>
  
  <p><code>java.lang.NullPointerException</code>.</p>
  
  <p>Here is the code. Any help would be greatly appreciated.</p>
  
  <pre><code>public class Table {
      public ArrayList&lt;String&gt; applicants;
      public String appArray[];
  
      public Table() {
          applicants = new ArrayList&lt;String&gt;();
      }
  
      public void addApplicant(String app) {
          applicants.add(app);
      }
  
      public void toArray() {
          int x = applicants.size();
          String[] appArray = new String[x];
          appArray = applicants.toArray(appArray);
      }
  
      public void list() {
          for (int i = 0; i &lt; applicants.size(); i++) {
              System.out.println(applicants.get(i));
          }
      }
  
      public void listArray() {
          for (int i = appArray.length; i &gt; 0; i--) {
              System.out.println(appArray[i]);
          }
      }
  }
  </code></pre>