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

后端 未结 3 1196
温柔的废话
温柔的废话 2021-01-29 14:47

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

3条回答
  •  醉话见心
    2021-01-29 15:15

    You may use streams for that.

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

提交回复
热议问题