com.olapdb.core.utils.CombinationUtil Maven / Gradle / Ivy
The newest version!
package com.olapdb.core.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class CombinationUtil {
public static List> combiantion(String[] items){
List> results = new Vector<>();
if(items==null||items.length==0){
return results;
}
List list=new ArrayList<>();
for(int i=0; i<=items.length; i++){
combine(items,0, i, list, results);
}
return results;
}
public static void combine(String[] items, int begin, int number, List list, List> results){
if(number==0){
List result = new ArrayList<>();
result.addAll(list);
results.add(result);
return ;
}
if(begin==items.length){
return;
}
list.add(items[begin]);
combine(items,begin+1,number-1, list, results);
list.remove(items[begin]);
combine(items,begin+1, number, list, results);
}
public static void main(String args[]){
String[] chs = {"a","b","c","d","e"};
List> results = combiantion(chs);
System.out.println("total = " + results.size());
for(List result : results){
System.out.println(result.toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy