+ 1
When do i use array lists over regular arrays?
It seems like they serve the same function, but there must be some reason both exist. Is one more efficient than the other?
3 Respuestas
+ 1
If I know how many numbers or whatever I want to save, I use arrays. Because you have to know the size of your array.
int[] number = new int [5];
If I don't know it I use a list.
ArrayList number =
new ArrayList ();
0
A list is also useful if you want to sort: https://www.sololearn.com/learn/Java/2183/?ref=app
0
An Array is a static object, List are collections so you may program to interfaces as bestpractices recommends.
For example: Given an array remove all elements when also exists at least one that is the double of it and return a sorted array of selectrd elements. This is better to wrap the array operate over it as a collection and then convert to array again.