There are many approaches to find the primes below a specific number. few better approaches will be Sieve of Eratosthenes and Segmented Sieve (for larger limit).
Below are the Java implementation of both.
Sieve of Eratosthenes Java Implementation
/**
* @param limit : The limit can not be large as 1000,000,000
* @return List of primes up to limit, i.e. in the range [0, limit]
*/
static List< integer > simpleSieve(int limit) {
boolean mark[] = new boolean[limit];
Arrays.fill(mark, true);
for (int p =...