Java 8: intstream to integer []

I'm writing a simple program that will eventually plot the runtime of various sorting algorithms written in Java The general interface of sorting algorithm is through a method: public void sort (comparable [] XS)

I try to use the flow mechanism of Java 8 to generate the following lines of random test cases:

public static IntStream testCase(int min,int max,int n) {
    Random generator = new Random();
    return generator.ints(min,max).limit(n);
}

My question is, how do I convert an object of type intstream to integer []?

Solution

You should convert IntStream box to flow < Integer>, and then call toArray to generate its array:

Integer[] arr = testCase(1,2,3).@R_849_2419@ed().toArray(Integer[]::new);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>