1
public class Array {
    public static void main(String[] args) {
        // initialize the array
        int size = 100000;
        int[] t = new int[size];

        // time traversing by :
        long start = System.nanoTime();
        for (int nums : t) {
            nums ++;
        }
        long end = System.nanoTime();
        System.out.println(end - start);

        // time traversing by index
        long start1 = System.nanoTime();
        for (int index = 0; index < size; index ++) {
            t[index] ++;
        }
        long end1 = System.nanoTime();
        System.out.println(end1 - start1);
    }
}

the result is:

842900

181700

So, what's going on here? What's colon's usage? I don't think a primitive array is iterator? Please tell me your opinion. Thank you guys. `

GARY LAU
  • 11
  • 1

0 Answers0