由网友(那朵云好甜)分享简介:我有一个二维数组像这样在Java 传输通信TV电视方法内存codemethodact我需要得到所有组合,如:{transmission,approach,methodact},{transmission,memory$c$c,methodact},{communication,approach,methodact}...![CAD矩形阵列新版,按ar后为何没有弹出阵列对话框,能够查看的也没有阵列角度 请问是什么原因](https://p.xsw88.cn/allimgs/daicuo/20230911/4435.png)
我有一个二维数组像这样在Java
传输通信TV电视
方法内存code
methodact
我需要得到所有组合,如:
{transmission,approach,methodact},{transmission,memory$c$c,methodact},{communication,approach,methodact},...
有人可以提供,将工作nXn的阵列,即使只有两行?一个例子
解决方案![CAD矩形阵列新版,按ar后为何没有弹出阵列对话框,能够查看的也没有阵列角度 请问是什么原因](https://p.xsw88.cn/allimgs/daicuo/20230911/4435.png)
这应该做的伎俩:
静态设置<列表<字符串>> allComb(字符串[] [] OPTS){
设置<列表<字符串>>结果=新的HashSet<列表<字符串>>();
如果(opts.length == 1){
对于(字符串S:选择采用[0])
results.add(新的ArrayList&其中;字符串>(Arrays.asList(多个)));
} 其他
对于(字符串str:选择采用[0]){
的String [] []尾= Arrays.copyOfRange(选1,opts.length);
对于(名单<字符串>梳子:allComb(尾)){
combs.add(STR);
results.add(梳);
}
}
返回结果;
}
I have an 2D-array like this in java
transmission communication tv television
approach memorycode
methodact
I need to get all combinations like:
{transmission,approach,methodact},{transmission,memorycode,methodact},{communication,approach,methodact},...
Can someone provide an example that will work for nXn arrays, even if it has only two rows?
解决方案This should do the trick:
static Set<List<String>> allComb(String[][] opts) {
Set<List<String>> results = new HashSet<List<String>>();
if (opts.length == 1) {
for (String s : opts[0])
results.add(new ArrayList<String>(Arrays.asList(s)));
} else
for (String str : opts[0]) {
String[][] tail = Arrays.copyOfRange(opts, 1, opts.length);
for (List<String> combs : allComb(tail)) {
combs.add(str);
results.add(combs);
}
}
return results;
}
相关推荐
最新文章