Java: what's the big-O time of declaring an array of size n?
问题 What is the running time of declaring an array of size n in Java? I suppose this would depend on whether the memory is zero\'ed out on garbage collection (in which case it could be O(1) ) or on initialization (in which case it\'d have to be O(n) ). 回答1: It's O(n) . Consider this simple program: public class ArrayTest { public static void main(String[] args) { int[] var = new int[5]; } } The bytecode generated is: Compiled from "ArrayTest.java" public class ArrayTest extends java.lang.Object{