Stack implemented using an ArrayList in Java