n個の配列はそれぞれ1数の重複しない組合せをとる

1566 ワード

package collection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Postion {
	List<String> strList = new ArrayList<String> ();
	List<String> strList2 = new ArrayList<String> ();
	int index = 0;
	public void getAll(List<String> list){
		if(list.size()>0){
			String[] s1 = list.get(0).split(",");
			for(String s1Str:s1){
			//	System.out.println(index>0);
				if(index==0){
					strList.add(s1Str);
					strList2 = strList;
				}else{
					for(String s2:strList){
						strList2.add(s2+","+s1Str);
					}
				}
			}
			strList = strList2;
			strList2 =new ArrayList<String> () ;
			index ++;
			list.remove(0);
			getAll(list);
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Postion p = new Postion();
		List<String> list = new ArrayList<String> ();
		list.add("3,5");
		list.add("2,4");
		list.add("4,9,10");
		p.getAll(list);
		
		Set set = new HashSet();
		for(String s:p.strList){
			
			set.add(s);
		}
		
		
		
		System.out.println(set);
	}

}