Reapply an array greater than or equal to the out-of-bounds length.
Then copy the contents of the original array to the new memory block through Sysmem.arraycopy.
If some elements are deleted, the capacity (container size) will be much larger than the actual length. You can rebuild the trimmed array and copy it.
This is also the implementation method in ArrayList. System.arraycopy is a native method with high replication efficiency.
Or you can look at the source code of arraylist.