I have the following class:
public class MyClass {
//...
public MyClass(int x, int y) {
//...
}
}
Now, I need to initialize 2D array with the items:
int rows;
int cols;
//initializing rows and cols
MyClass[][] arr = new MyClass[rows][cols];
//how to initialize arr[x][y] with
//new MyClass(x, y) with streams API
I looked at this example, but it doesn't work in my case: Java 8 Stream and operation on arrays. They use a single IntStream
.
Question: Of course I can use nested for loops, but I think it's now old-style and is considering bad. So how to apply streams api and initilize it in Java 8 way?