When we write -
ArrayList al=new ArrayList(10);
Sometimes write an array like -
RefVar = new dataType[10];
What is happening in memory? whether the memory is located in continuous order or scattered order?
In principle, the Java language - neither the language spec nor the VM spec - doesn't mention how objects and arrays are to be implemented and does not guarantee consecutive memory allocation.
In practice, though, arrays are consecutive (only in their first dimension!), and ArrayList is implemented using an array, therefore the item references inside it are consecutive. Although the implementation of ArrayList includes other fields which are separate from the actual array.
If you add an element to an ArrayList whose internal array is already full, it will internally allocate a new, bigger array and copy all the existing element references to it. So even when that happens, the element references will still be consecutive (in practice).