title: Replace the value of one column from another column in spark dataframe
body: <p>I have a dataframe like below</p>
  
  <pre><code>+---+------------+----------------------------------------------------------------------+
  |id |indexes     |arrayString                                                           |
  +---+------------+----------------------------------------------------------------------+
  |2  |1,3         |[WrappedArray(3, Str3), WrappedArray(1, Str1)]                        |
  |1  |2,4,3       |[WrappedArray(2, Str2), WrappedArray(3, Str3), WrappedArray(4, Str4)] |
  |0  |1,2,3       |[WrappedArray(1, Str1), WrappedArray(2, Str2), WrappedArray(3, Str3)] |
  +---+------------+----------------------------------------------------------------------+
  </code></pre>
  
  <p>i want to loop through arrayString and get the first element as index and second element as String. Then replace the indexes with String corresponding to the index in arrayString. I want an output like below.</p>
  
  <pre><code>+---+---------------+
  |id |replacedString |
  +---+---------------+
  |2  |Str1,Str3      |
  |1  |Str2,Str4,Str3 |
  |0  |Str1,Str2,Str3 |
  +---+---------------+
  </code></pre>
  
  <p>I tried using the below udf function.</p>
  
  <pre><code>  val replaceIndex = udf((itemIndex: String, arrayString: Seq[Seq[String]]) =&gt; {
        val itemIndexArray = itemIndex.split("\\,")
      arrayString.map(i =&gt; {
        itemIndexArray.updated(i(0).toInt,i(1))
      })
      itemIndexArray
    })
  </code></pre>
  
  <p>This is giving me error and i am not getting my desired output. Is there any other way to achieve this. I cant use explode and join as i want the indexes replaced with string without losing the order.</p>
  
  <p>. </p>