title: How to print the list of map values using scala
body: <p>I have written the following code</p>
  
  <pre><code>val list = List(
    Map("empid" -&gt; "12", "empName" -&gt; "Rohan", "depId" -&gt; "201"),
    Map("empid" -&gt; "13", "empName" -&gt; "swathi", "depId" -&gt; "202")
  ).flatten.toMap
  
  val mapRDD= sc.parallelize(Seq(list))
  
  val columns=mapRDD.take(1).flatMap(a=&gt;a.keys)
  
  val columnval=mapRDD.take(2).flatMap(a=&gt;a.keys)
  
  val resultantDF=mapRDD.map{value=&gt;
  
        val list=value.values.toList
  
        (list(0),list(1),list(2))
  
        }.toDF(columns:_*)
  
  
  
  resultantDF.show()
  </code></pre>
  
  <p>i am expecting the below output,</p>
  
  <p>+-----+-------+-----+</p>
  
  <p>|empid|empName|depId|</p>
  
  <p>+-----+-------+-----+</p>
  
  <p>|   12| Rohan|  201|</p>
  
  <p>|   13|SWATHI|202 |</p>
  
  <p>but i am getting only,</p>
  
  <p>+-----+-------+-----+</p>
  
  <p>|empid|empName|depId|</p>
  
  <p>+-----+-------+-----+
  |   13|SWATHI|202</p>
  
  <p>Please let me know where i am doing the mistake.</p>