title: Select the last element of an Array in a DataFrame
body: <p>I'm working on a project and I'm dealing with some nested JSON date with a complicated schema/data structure. Basically what I want to do is filter out one of the columns, in a dataframe, such that I select the last element in the array. I'm totally stuck on how to do this. I hope this make sense.</p>
  
  <p>Below is an example of what I'm trying to accomplish:</p>
  
  <pre><code>val singersDF = Seq(
    ("beatles", "help,hey,jude"),
    ("romeo", "eres,mia"),
    ("elvis", "this,is,an,example")
  ).toDF("name", "hit_songs")
  
  val actualDF = singersDF.withColumn(
    "hit_songs",
    split(col("hit_songs"), "\\,")
  )
  
  actualDF.show(false)
  actualDF.printSchema() 
  
  +-------+-----------------------+
  |name   |hit_songs              |
  +-------+-----------------------+
  |beatles|[help, hey, jude]      |
  |romeo  |[eres, mia]            |
  |elvis  |[this, is, an, example]|
  +-------+-----------------------+
  root
   |-- name: string (nullable = true)
   |-- hit_songs: array (nullable = true)
   |    |-- element: string (containsNull = true)
  </code></pre>
  
  <p>The end goal for the output would be the following, to select the last "string" in the hit_songs array. </p>
  
  <p>I'm not worried about what the schema would look like afterwards.</p>
  
  <pre><code>+-------+---------+
  |name   |hit_songs|
  +-------+---------+
  |beatles|jude     |
  |romeo  |mia      |
  |elvis  |example  |
  +-------+---------+
  </code></pre>