(String[] args)
| 16 | .noneMatch(i -> n % i == 0); |
| 17 | } |
| 18 | public static void main(String[] args) |
| 19 | throws IOException { |
| 20 | Timer timer = new Timer(); |
| 21 | List<String> primes = |
| 22 | iterate(2, i -> i + 1) |
| 23 | .parallel() // [1] |
| 24 | .filter(ParallelPrime::isPrime) |
| 25 | .limit(COUNT) |
| 26 | .mapToObj(Long::toString) |
| 27 | .collect(Collectors.toList()); |
| 28 | System.out.println(timer.duration()); |
| 29 | Files.write(Paths.get("primes.txt"), primes, |
| 30 | StandardOpenOption.CREATE); |
| 31 | } |
| 32 | } |
| 33 | /* Output: |
| 34 | 1635 |