What difference and benefit does an array have against the listarray

0

Hi, I'm a java programmer and I'm seeing some that say it's better ArrayList than a Array normal?

I honestly do not see difference I see it the same

    
asked by simon 03.02.2017 в 07:03
source

2 answers

3
  • An ArrayList has a dynamic size, while that of an Array is defined in its creation.
  • An ArrayList can not contain data Primitives, only Objects.
  • The ArrayList allows you to verify that the data that are added to the collection are of the correct type in time of compilation.
  • The Array can be of several dimensions, the ArrayList it is one-dimensional (although it can be an ArrayList of ArrayLists).
answered by 03.02.2017 / 08:00
source
1

Hello as they indicate in the previous answer an ArrayList can change size as needed at runtime, the ArrayList Class implements the List interface

List<Integer> lista = new ArrayList<>();

The Integer value between the diamond operator (< >) indicates the type of object to be entered, because if you try to do this: lista.add("1"); will not compile since it asks for an Integer (1,2,3 .. .) and trying to send a String.

Greetings.

    
answered by 06.02.2017 в 15:44