Fastest strategy to form and sort an array of positive integers
In Java, what is faster: to create, fill in and then sort an array of ints like below int[] a = int[1000]; for (int i = 0; i < a.length; i++) { // not sure about the syntax a[i] = Maths.rand(1, 500) // generate some random positive number less than 500 } a.sort(); // (which algorithm is best?) or insert-sort on the fly int[] a = int[1000]; for (int i = 0; i < a.length; i++) { // not sure about the syntax int v = Maths.rand(1, 500) // generate some random positive number less than 500 int p = findPosition(a, v); // where to insert if (a[p] == 0) a[p] = v; else { shift a by 1 to the right a[p] =