arrayWithCapacity is an optimization - it's optional. If you know the number of elements ahead of time, the system can allocate memory in one system call and in one memory block. Otherwise, the system will have to resize the array later, adding a few more elements and, as a rule, slowly, requiring additional allocations and, possibly, copying data from the old buffer to the new buffer.
EricS source
share