Remove is not working in arraylist?
<p>I have project to do and i have to add people to the database and then remove them but when i try to remove a person from the arraylist it works but when i try to add more in i get index out of bounds exception?</p>

<pre><code>public void removePerson(List&lt;Person&gt; CrecheList) {
    if (CrecheList.isEmpty()) {
        JOptionPane.showMessageDialog(null, "You need a Child or parent in the database", "Error", JOptionPane.INFORMATION_MESSAGE);
    } else {
        String pickid = JOptionPane.showInputDialog(null, "Please Enter an id");
        int id = Integer.parseInt(pickid);
        Iterator&lt;Person&gt; i = CrecheList.iterator();
        while (i.hasNext()) {
            Person p = i.next();
            if (p.getID() == id) {
                i.remove();
            } else {
                JOptionPane.showMessageDialog(null, "There is no such person in the database", "Child name", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }
}
</code></pre>

<p>and when i remove and try to add more into the arrylist i get index out of bounds?</p>
