
i want to retrieve k,v-pairs from a hashmap. the entrys are like this:
a = 3,4 b = 5,6
and so on. i need combinations of these values.
a=3, b=5. a=3, b=6. a=4, b=5. a=4, b=6.
I don't know how many keys and how many entrys the values have. with entryset i can get the values but not combinations. it looks like recursion but how?

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class R2T2Generator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
R2T2Generator r2t2generator=new R2T2Generator();
Map<String,String[]>map=new TreeMap<String,String[]>();
map.put("ProductSet",new String[]{"IA","EA"});
map.put("role",new String[]{"Internal","External"});
map.put("mode",new String[]{"D"});
r2t2generator.mapPermute(map, "");
}
public void mapPermute(Map<String, String[]> map, String currentPermutation) {
String key = map.keySet().iterator().next(); // get the topmost key
// base case
if (map.size() == 1) {
for (String value : map.get(key)) {
System.out.println(currentPermutation + key + "=" + value);
}
} else {
// recursive case
Map<String, String[]> subMap = new TreeMap<String, String[]>(map);
for (String value : subMap.remove(key)) {
mapPermute(subMap, currentPermutation + key + "=" + value + ", ");
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.