在一次采访中,我被问到以下问题:
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] array = new int [10000];
for (int i = 0; i < array.length; i++) {
// do calculations
}
for (int x = array.length-1; x >= 0; x--) {
// do calculations
}
}
Run Code Online (Sandbox Code Playgroud)
}
从末尾或从头开始迭代数组是否相同?据我了解,由于复杂性是恒定的,即 O(1) ,所以它会是一样的?我对么?
我还被问到与 Java 中的其他集合(例如 LinkedList)相比,ArrayList 的复杂性。
谢谢你。