我编写了一个代码来获取字符串数组合,如下所示
static void printCombination(String arr[], int n, int r)
{
// A temporary array to store all combination one by one
String data[]=new String[r];
// Print all combination using temprary array 'data[]'
combinationUtil(arr, data, 0, n-1, 0, r);
}
static void combinationUtil(String arr[], String data[], int start,
int end, int index, int r)
{
// Current combination is ready to be printed, print it
if (index == r)
{
for (int j=0; j<r; j++)
System.out.print(data[j]+" ");
System.out.println("");
return;
}
// replace index with all possible elements. The condition
// "end-i+1 >= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);
}
}
并从main调用该函数,如下所示
int r = 2;
int n = arrayOfPatches.length;
printCombination(arrayOfPatches, n, r);
所以现在在进行组合时,它将数据存储在单个数组中,如下所示 ABCD PQRS ABCD XYZ PQRS XYZ
所以现在我需要放入一个二维数组,所以我应该读它。所以请帮助我如何在java中转换成二维数组