【发布时间】:2016-03-03 10:49:34
【问题描述】:
我有一个包含以下值的地图:
TreeMap<String, String> params = new TreeMap<>();
params.put("Has GPS – based Lat/Long", "Yes, No");
params.put("Ad Size", "320x480, 300x250");
params.put("Integration", "Direct, Indirect");
params.put("Vdo Ad Formats", "Max, Min, Med");
params.put("App/Mobile Targeting", "Mobile Web, App");
现在我想要来自以下值的所有组合:
320x480, Yes, Direct, Max, Mobile Web
320x480, Yes, Direct, Max, App
300x250, Yes, Direct, Max, APP
300x250, Yes, Indirect, Max, Mobile Web
300x250, Yes, Direct, Max, Mobile Web
300x250, No, Direct, Max, Mobile Web
etc....
尝试了解决方案,它根本没有给我所有的组合。
List<String> keysList = new ArrayList<>();
keysList.addAll(params.keySet());
//1. iterating the keys list
for(int i=0; i<keysList.size(); i++)
{
String x = "";
String [] values_00 = map.get(keysList.get(i)).split(",");
//2. iterating array of values
for(int a0=0; a0<values_00.length; a0++)
{
//3. Iterating the next available keys from the list
for(int j=i+1; j<keysList.size(); j++)
{
String [] values_01 = map.get(keysList.get(j)).split(",");
//4. Iterating values of next array of values of next available keys
for(int a1=0; a1<values_01.length; a1++)
{
x = values_00[a0] + " " + values_01[a1];
System.out.println(x);
}
}
}
}
【问题讨论】:
标签: java combinations