If JVM is not able to allocate requested amount of memory it’ll throw
OutOfMemoryError
That’s it. Actually JVM memory allocation has only two possible outcomes:
- Application is given requested amount of memory.
- JVM throws OutOfMemoryError.
There is no intermediate options, like some amount of memory is allocated.
It has nothing to do with ArrayList, it’s a JVM issue. If you asking whether ArrayList somehow manages this situation in a special way – then answer is “No, it does not.” It just tries to allocate amount of memory it needs and lets JVM think about the rest.