What's the run time of String.toCharArray() in java? The source code is
public char[] toCharArray() { // Cannot use Arrays.copyOf because of class initialization order issues char result[] = new char[value.length]; System.arraycopy(value, 0, result, 0, value.length); return result; } Does System.arrayCopy? have run time of O(n)? The source code doesn't really say much about how it's implemented. Does it go through every element and copies it? Thanks.
O(1). I would say, the run-time is stillO(N), whereNis the number of blocks. Granted this is a faster approach, you still have to copy all of the blocks.