Inventory program in java
<p>Hi guys I am making an inventory program and I am having trouble with the stockItem remove method. I want it to remove item at the given index and return the removed item. And return null if the index is invalid.</p>

<p>This is my code so far. Please scroll to the bottom to see what I'm talking about.</p>

<pre><code>import java.util.ArrayList;

public class Inventory {
    private ArrayList&lt;StockItem&gt; stock;

    public Inventory() {
        stock = new ArrayList&lt;StockItem&gt;();
    }

    public void addStockItem(StockItem item) {
        stock.add(item);
    }

    public int size() {
        return stock.size();
    }

    public String toString() {
        String result = "";
        for(StockItem item: stock)
            result+=item.toString()+"\n";
        return result;
    }

    public boolean isValidIndex(int index) {
        return index &gt;=0 &amp;&amp; index &lt; stock.size();
    }


    public StockItem getItem(int index) {
         if (index &lt; 0 || index &gt;= this.stock.size()){
               return null;
         }
         return this.stock.get(index);
    }


     /**
     * 
     * @param index
     * @return null if index is invalid, otherwise
     * remove item at the given index and return the 
     * removed item.
     */
    public StockItem remove(int index) {
        return null; //I need to do this part
    }


}
</code></pre>