B. Sen
B. Sen

Reputation: 27

Time complexity of "add" from Apache Commons Lang class 'ArrayUtils'

I am wondering if this method of adding to primitive array is still constant time?

char[] arrayA = {'b', 'c'};
char[] arrayB = ArrayUtils.add(arrayA, 0, 'a');
// arrayB: [a, b, c]

Upvotes: 0

Views: 90

Answers (1)

Veselin Davidov
Veselin Davidov

Reputation: 7071

You can look at the implementation here

Basically in the end it uses System.arraycopy which has a complexity of O(n)

Upvotes: 1

Related Questions