Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks to me like you really want a <a href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multimap.html" rel="nofollow noreferrer">MultiMap</a>. In particular, <a href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ArrayListMultimap.html" rel="nofollow noreferrer">ArrayListMultimap</a> allows duplicate entries:</p> <pre><code>ArrayListMultimap&lt;String, String&gt; map = ArrayListMultimap.create(); for each line in file: parse key k for each value in line: parse value v map.put(k, v); for (Map.Entry&lt;String,String&gt; entry : map.entries()) { String key = entry.getKey(); String value = entry.getValue(); } </code></pre> <hr> <p>If you want a cartesian product of maps, you could compute that directly using recursion, or you could iterate over the maps: create a list of iterators and iterate odometer-style; when iterator N reaches its end, advance iterator N+1 and reset iterators 1..N.</p> <hr> <p>Just poked around and found this SO question: <a href="https://stackoverflow.com/questions/1719594/iterative-cartesian-product-in-java">Iterative Cartesian Product in Java</a></p> <p>So I'd recommend you use guava's <a href="http://guava-libraries.googlecode.com/svn/tags/release04/javadoc/com/google/common/collect/Sets.html#cartesianProduct%28java.util.Set...%29" rel="nofollow noreferrer">Sets.cartesianProduct</a> for the cartesian product. Here's my poking around code, which you could adapt to your input logic:</p> <pre><code> String key1 = "a"; Set&lt;Integer&gt; values1 = Sets.newLinkedHashSet(Arrays.asList(1, 2, 3, 4 )); String key2 = "b"; Set&lt;Integer&gt; values2 = Sets.newLinkedHashSet(Arrays.asList(5, 6, 7)); String key3 = "c"; Set&lt;Integer&gt; values3 = Sets.newLinkedHashSet(Arrays.asList(8, 9)); List&lt;String&gt; keys = Arrays.asList(key1, key2, key3); Set&lt;List&lt;Integer&gt;&gt; product = Sets.cartesianProduct(values1, values2, values3); for (List&lt;Integer&gt; values : product) { for (int i = 0; i &lt; keys.size(); ++i) { String key = keys.get(i); int value = values.get(i); System.out.print(key + "=" + value + "; "); } System.out.println(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload