fork download
  1. package main;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.math.BigInteger;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Scanner;
  11.  
  12. public class Main {
  13.  
  14. public static void main(String[] args) throws IOException {
  15.  
  16. final int NUM_ITEMS = 1000000;
  17.  
  18. List<Integer> list = new ArrayList<>(NUM_ITEMS);
  19.  
  20. {
  21. // Integer[] intArray = new Integer[NUM_ITEMS];
  22. // for (int i = 0; i < NUM_ITEMS; ++i) {
  23. // intArray[i] = i;
  24. // }
  25.  
  26. // Insert
  27. long tStart = System.currentTimeMillis();
  28. for (int i = 0; i < NUM_ITEMS; ++i) {
  29. list.add(i);
  30. //list.add(intArray[i]);
  31. }
  32. long tEnd = System.currentTimeMillis();
  33.  
  34. System.out.println("Insert dt:" + (tEnd - tStart));
  35. }
  36.  
  37.  
  38. {
  39. // Read
  40. long sum = 0;
  41. long tStart = System.currentTimeMillis();
  42. for (int i = 0; i < NUM_ITEMS; ++i) {
  43. sum += list.get(i);
  44. }
  45. long tEnd = System.currentTimeMillis();
  46.  
  47. System.out.println("Read dt:" + (tEnd - tStart));
  48. System.out.println("Read sum: " + sum);
  49. }
  50.  
  51. }
  52. }
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:18: illegal start of type
		List<Integer> list = new ArrayList<>(NUM_ITEMS);
		                                   ^
1 error
stdout
Standard output is empty