Arraylist and Arrays

What's the difference between

ArrayList<Object> al = new ArrayList<Object>(100);

and

Object[] ar = new Object[100];

Is there a difference in internal implementation, that is, in memory? Make an internal backup of 100 slots in memory?

-1
source share
4 answers

An ArrayList<Object>has support Object[]. The backup array will be “modified” (a new array will be created and the old data will be copied) if you may have overloaded the size and additions, perhaps.

List implementations also provide additional methods for working with them.

Another thing is that you can use Generics (1.5) with lists.

+5
source

ArrayList List - , . (Object []) .

0

No, both do not mean the same in ArrayList < Object > al = new ArrayList< Object >(100);just define initialCapacity, in the future you can add n number of elements but Object[] ar = new Object[100];you can not add elements after 100 size

0
source

ArrayList can dynamically grow or shrink at runtime, arrays cannot. ArrayList is a list implemented using an array. It provides you with many functions (mainly list operations) that are not provided.

0
source

Source: https://habr.com/ru/post/1568792/


All Articles