Time complexity of System.arraycopy(...)?

Kowser picture Kowser · Aug 23, 2011 · Viewed 18.3k times · Source

System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) is a native method.

What is the time complexity for this method?

Answer

bragboy picture bragboy · Aug 23, 2011

It will have to go through all the elements in the array to do this. Array is a unique data structure where you have to specify a size when you initialize it. Order would be the source array's size or in Big O terms its O(length).

Infact this happens internally in an ArrayList. ArrayList wraps an array. Although ArrayList looks like a dynamically growing collection, internally it does an arrycopy when it has to expand.