title: How to convert Generic Arraylist into Array in Java?
body: <p>I need to change this program to use a array instead of an arraylist. Apparently I need to create an array of objects and cast it to E[] but I don't understand how to do this. Any help is appreciated.</p>
  
  <pre><code>public class GenericStack&lt;E&gt; {
    private java.util.ArrayList&lt;E&gt; list = new java.util.ArrayList&lt;E&gt;();
  
    public int getSize() {
      return list.size();
    }
  
    public E peek() {
      return list.get(getSize() - 1);
    }
  
    public E push(E o) {
      list.add(o);
      return o;
    }
  
    public E pop() {
      E o = list.get(getSize() - 1);
      list.remove(getSize() - 1);
      return o;
    }
  
    public boolean isEmpty() {
      return list.isEmpty();
    }
  }
  </code></pre>