Question: I have some lines of text, and then their relevance weight.

```
Weight, Text
10, "I like apples"
20, "Someone needs apples"

```

Is it possible to get the combinations, keeping the values in the weights column? Something like:

```
weight, combinations
10, [I like]
10, [I apples]
10, [like apples]
20, [someone needs]
20, [someone apples]
20, [needs apples]

```

"Generate n-grams from Pandas column while persisting another column" (unsolved) is a similar question, but it is unsolved.

Thanks!!!

Answer: 
To fill the first row in 2D array, use `Arrays.fill`, to fill the rest of the rows, use [`Arrays.copyOf`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Arrays.html#copyOf(T%5B%5D,int)).

Next, it's better to implement separate methods to perform different tasks:

1. Create and fill the grid
2. Print the grid

```java
static String[][] fillGrid(int rows, int cols, String cell) {
    String[][] grid = new String[rows][cols];

    String[] row = new String[cols];
    Arrays.fill(row, cell);
    grid[0] = row;
    for (int i = 1; i < rows; i++) {
        grid[i] = Arrays.copyOf(row, cols);
    }

    return grid;
}

static void printGrid(String[][] grid) {

    for (int i = 0; i < grid.length; i++) {
        if (i == 0) {
            System.out.print("   ");
            for (int j = 0; j < grid[0].length; j++) {
                System.out.printf("%2d ", j + 1);
            }
            System.out.println();
        }
        for (int j = 0; j < grid[i].length; j++) {
            if (j == 0) {
                System.out.printf("%2d:", i + 1);
            }
            System.out.printf("%2s ", grid[i][j]);
        }
        System.out.println();
    }
}

```

Then they may be tested like this:

```java
public static void main(String ... args) {
    String[][] grid = fillGrid(8, 8, "x");
    printGrid(grid);
}

```

The output will be as follows:

```
    1  2  3  4  5  6  7  8 
 1: x  x  x  x  x  x  x  x 
 2: x  x  x  x  x  x  x  x 
 3: x  x  x  x  x  x  x  x 
 4: x  x  x  x  x  x  x  x 
 5: x  x  x  x  x  x  x  x 
 6: x  x  x  x  x  x  x  x 
 7: x  x  x  x  x  x  x  x 
 8: x  x  x  x  x  x  x  x 

```
The "import java.util.arrays" needs to be above the class definition at the top of the file.