Array x Arraylist

Asked

Viewed 42 times

0

Yesterday I made a question on how to use a Two-dimensional Array dynamically, so I ended up getting a reply to use a Arraylist, and this served perfectly for my case, however, from that it generated me the doubt, when I should use one or the other?

Even in simple cases, where it would not be necessary to modify the data, I realized that the Arraylist served me as well as a Array normal, then I would like to know, when it is most necessary or right to use a Array than a Arraylist?

  • 4

    If you need to store a list of some primitive type, you will only get it with arrays, because with Arraylist you cannot create with primitive types, only with Wrappers. Array is best for when you have control over the amount of data to be stored, and know that it will not be changed, because once created, there is no expansion or reduction, and already with arraylist, although it is possible to set initial size, she is expandable without need of your intervention.

  • 6

    Ah, from the performative point of view, arrays are faster than Collections, but only for cases where the creation, reading and exchange of data is intense. For the vast majority of cases, it is not possible to notice this difference.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.