title: Java : how to add columns to dataframe based on a list of objects
body: <p>I have to add columns to my dataframe and columns= List so i have to iterate over this list of objects:</p>
  <pre><code>columns=[
  {val1=&quot;A&quot;,val2=&quot;num1&quot;},
  {val1=&quot;B&quot;,val2=&quot;num2&quot;},
  {val1=&quot;C&quot;,val2=&quot;num3&quot;},
  {val1=&quot;D&quot;,val2=&quot;num4&quot;}
  ]
  </code></pre>
  <p><strong>mydataframe</strong></p>
  <pre><code> |nom     |prenom   | age |
   |arnauld | simpson | 43  |
  </code></pre>
  <p><strong>expected result is:</strong></p>
  <pre><code> |nom     |prenom   | age | A   | B  | C  | D  |
   |arnauld | simpson | 43  |num1 |num2|num3|num4|
  </code></pre>
  <p>what i tried is :</p>
  <pre><code>Iterator&lt;Myclass&gt; iterator = cols.iterator();
  Dataset&lt;Row&gt; result=myDf;
  while (iterator.hasNext()) {
  
    Myclass res = iterator.next();
  
    String val1= res.getVal1();
    String val2= res.getVal2();
   
  
    result = myDf.withColumn(val1, expr(val2));
    result.show();
  
  }
  </code></pre>
  <p>but i don't have the result expected, i only have the last object (val1=&quot;D&quot;,val2=&quot;num4&quot;).
  How can i obtain my expected result please?</p>