title: Lists in Groovy
body: <p>I have three lists :<br/>
  <code>HeaderList : [A, B, C]</code><br/>
  <code>SubHeaderList : [a1, a2, b1, b2, b3, c1]</code><br/>
  <code>HeaderSubHeaderMapping : [2, 3, 1]</code></p>
  
  <p>I need to create a new list which will be : <code>[A_a1, A_a2, B_b1, B_b2, B_b3, C_c1]</code><br/>
  The HeaderSubHeaderMapping gives how many subheaders in the SubHeaderList belong to headers in the HeaderList.<br/>
  For example : <code>Header A</code> will have <code>2</code> subheaders <code>a1</code> and <code>a2</code> as indicated by the <code>HeaderSubHeaderMapping</code> <br/>
  I am currently using this code which gives me the required output.</p>
  
  <pre><code>def lHeaderList = ["A", "B", "C"]
  def lSubHeaderList = ["a1", "a2", "b1", "b2", "b3", "c1"]
  def lHeaderSubHeaderMapping = [2, 3, 1]
  
  def lKeyList = []
  def lIndex = 0
  for(int i = 0; i &lt; lHeaderList.size(); i++) {
      for(int j = 0; j &lt; lHeaderSubHeaderMapping.get(i); j++) {
          lKeyList &lt;&lt; (lHeaderList.get(i) + "_" + lSubHeaderList.get(lIndex))
          lIndex++
      }
  }
  println lKeyList
  </code></pre>
  
  <p>But I would like to know is there any groovier way to achieve this?</p>