EvbCFfp1XB

problem and my answer.

October 2015

Sometimes, It takes long time to add a element into hash set.

import java.util.HashSet;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < 1e9; i++) {
            double start = System.nanoTime() * 1e-9;
            set.add(i);
            double end = System.nanoTime() * 1e-9;
            if (end - start > 1.0) {
                System.out.println("time, " + (end - start));
                break;
            }
        }
    }
}

このページのトップヘ