ArrayList


For when you need dynamically allocated Arrays(like any other language)


With adding elements, it is in O(1) time, since you would just create an element and place the value in.


When you add repeatedly, you create a new array, copy all of the values, and then destroy the old array.


With 1030, only 11 times would be copying and destroying, while the other times would be copying. With how the appending works, it doubles the size, over and over again.



With a random spot, you will need to shift the elements left over.


When it comes down to it, create a new array rather than doing too many removing and shifting. Like from 100 to 2.


Here with this, if you have 5/8th of a arrayList filled, the size would be 5, while the capacity would be 8.


Better you know your limit/final capacity, rather than infinitely copying/appending over and over.


Use the third one, either 3 or 4 is good.


If you want to append an element, use add.


With clear, it clears the size, while capacity still the same.

When increasing past bounds, capacity doubles, while size goes up by one.

When decrasing, capacity is the same as initial one, while size goes down one.


When it comes to contains, it assumes that it isn’t empty, so make sure to check if.Empty() first, then searching for it.



With this, unlike regular arrays, like the old print either using the old way of using a method, or using toString(), or printing the languages.


With

arr.remove(pos)// it will remove the arraylist at that position(when you use int only)
arr.remove(Integer.valueOf(pos)// it will remove the pos value instead.

Two ways, either reset I or start from the back. Second one not always applicable like, for instance, with adding the two previous one to determine a new one, would need a new function for that.