The index of an ArrayList starts at 0 and it cannot equal the size of the ArrayList, just like we mentioned with strings and arrays. ArrayList is a class, which means it has its own methods like the String class does. Take a look at the commonly used methods in the ArrayList class and their functions.
These are the important methods to learn for an ArrayList:
add[value] or add[index,value]
Adds an element to the end of an ArrayList. The method returns "true" if it is treated as a boolean value. When you add a specific index as a parameter, it will add the value at the specified index and move everything else after it up by one index.
remove[index]
Removes an element from the ArrayList. It can return a reference to the deleted element if it is called. The method will shift the other elements down an index to account for the deleted element.
set[index, value]
Combines add[] and remove[] by replacing the value at "index" with the new "value"
get[index]
Accesses the element at a particular index.
size[]
Returns the current length of the ArrayList. This method is important as the size may change when using the methods above.
View Full Version
It's 100% FREE!