title: How to multiply all elements of one list with first element of second list in java?
body: <p>I have two lists; list1 and list2. list1 consists of 5 elements and list2 consists 18 elements and each element of list2 in turn consist of a (41X41) 2D array. How can I multiply the first element of list1 with all the 18 element of list2? I have to do this multiplication for all the five elements of list1.</p>
  
  <p>I tried</p>
  
  <pre><code>List&lt;List&lt;Double&gt;&gt; Q = new ArrayList&lt;List&lt;Double&gt;&gt;();   
  for (int i = 0; i &lt; list1.size(); i++){
      List&lt;Double[][]&gt; list=new ArrayList&lt;&gt;(list2.size());
      for (int j = 0; j &lt; list2.size(); j++){
          Double P[][] = new Double[41][41];
          for (int k = 0; k &lt; 41; k++){
              for (int l = 0; l &lt; 41; l++){
                  P[k][l] = list1.get(i) * list2.get(j)[k][l];
                  }
              }
              list.add(P);
          }
          Q.add(list);
       }
  </code></pre>
  
  <p>Is there a better way to do it to make it less complicated to understand?</p>