Discussion 3 Though arrays and array lists are very similar, they are different data types that store and allow manipulation of the values stored differently. Arrays are used to store a sequence of values of a data type that is specified during the array initialization. Array lists also store a sequence of values of a specific class type that is specified during initialization. Unlike arrays, array lists cannot be initialized with integers or floating-point numbers. In order to store numerical values in an array list, the wrapper class must be used. An example of this is using Integer instead of int and Double instead of double.
The biggest difference between the two is the size of an array versus the size of an array list. The array is limited to the size that it is given at initialization and can have elements filled with values upon initialization. If more elements are needed, the copyOf method is used; this will copy the contents of the array into a newly initialized array and allow a new array size to be set. However, the array list size increases and decreases as values are added and removed from it, but elements cannot be filled during initialization.
To access a specific element of an array, we use the [ ] operator to access the index of the element you want to access, which is put inside the braces. This is also the case for adding or changing a value of an element in an array. First, you must access the element and assign it a new value. For array lists, simply use the get method to access a specific element and add to the array; all that is needed is the add method. For removing an element in an array, we need to use a common algorithm that will remove an element from the beginning or the end or a slightly more complex algorithm if it is somewhere in the middle. While array lists use the remove method, place the element index that needs to be removed inside the parentheses.
Overall, I feel that using arrays is best when the number of elements needed is known from the beginning. This will prevent having to copy the array into a new one just to be able to have a bigger array to add the new values. This can be done by using an array list, which eliminates the need to copy the array to a new, bigger array.