package main;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
final int NUM_ITEMS = 1000000;
List<Integer> list = new ArrayList<>(NUM_ITEMS);
{
// Integer[] intArray = new Integer[NUM_ITEMS];
// for (int i = 0; i < NUM_ITEMS; ++i) {
// intArray[i] = i;
// }
// Insert
long tStart
= System.
currentTimeMillis(); for (int i = 0; i < NUM_ITEMS; ++i) {
list.add(i);
//list.add(intArray[i]);
}
long tEnd
= System.
currentTimeMillis();
System.
out.
println("Insert dt:" + (tEnd
- tStart
)); }
{
// Read
long sum = 0;
long tStart
= System.
currentTimeMillis(); for (int i = 0; i < NUM_ITEMS; ++i) {
sum += list.get(i);
}
long tEnd
= System.
currentTimeMillis();
System.
out.
println("Read dt:" + (tEnd
- tStart
)); System.
out.
println("Read sum: " + sum
); }
}
}
cGFja2FnZSBtYWluOwoKaW1wb3J0IGphdmEuaW8uQnVmZmVyZWRSZWFkZXI7CmltcG9ydCBqYXZhLmlvLkZpbGVOb3RGb3VuZEV4Y2VwdGlvbjsKaW1wb3J0IGphdmEuaW8uRmlsZVJlYWRlcjsKaW1wb3J0IGphdmEuaW8uSU9FeGNlcHRpb247CmltcG9ydCBqYXZhLm1hdGguQmlnSW50ZWdlcjsKaW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuTGlzdDsKaW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewoKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBJT0V4Y2VwdGlvbiB7CgoJCWZpbmFsIGludCBOVU1fSVRFTVMgPSAxMDAwMDAwOwoJCQoJCUxpc3Q8SW50ZWdlcj4gbGlzdCA9IG5ldyBBcnJheUxpc3Q8PihOVU1fSVRFTVMpOwoKCQl7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