0

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]
3
  • 1
    Have you looked at the implementation? If not, why not? Commented Sep 25, 2019 at 12:35
  • @Michael all it says is this: Copies the given array and adds the given element at the end of the new array. I do not know how to tell the answer to my question from that Commented Sep 25, 2019 at 12:39
  • I said the implementation, not the documentation. Commented Sep 25, 2019 at 12:43

1 Answer 1

1

You can look at the implementation here

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.