Fırat Kıyak Fırat Kıyak - 21 days ago 5
Java Question

What is the most efficent way to generate unique double values in Java

There are methods such as searching for duplicates but I wonder if there is a better solution for this task.

Answer

You may use streams for that.

double[] array = new Random().doubles()
                             .distinct()
                             .limit(500) // How many you want.
                             .toArray();
Comments