ArrayLists are so useful and so convenient to use so you will usually see ArrayList applications in the FRQ portion of the AP exam. The main difference between a normal array and an ArrayList is that an ArrayList has variable length which means you can keep adding or removing elements to/from the array without having to set a set length. ArrayLists can only hold objects so it can’t hold primitive data types; however, this can be circumvented through Java’s wrapper classes.
The ArrayList also has a set of its own methods that you can use. All of the methods can be found in the APCS Appendix B under interface java.util.List methods. Take note of what parameters and return types these methods have. You will most likely use them if there is an ArrayList FRQ on the exam (which is pretty likely).
Here is the basic declaration and instantiation:
ArrayList name = new ArrayList <data type> ();
So if I were to make an ArrayList called roster and put in three names, it would look like this:
ArrayList roster = new ArrayList<String>();
That’s it. I think I’ve covered the basics. If any of you guys have any questions, comment below or fill out our contact page.
Otherwise, if this was helpful, let us know and click the like button.