0

I am new to Scala and could use some help. I have an RDD that is Array[Array[String]]. I need to extract the 1st element in each internal array. Sample records look like:

res21: Array[Array[String]] = Array (Array(217.150.149.167, -, 4712, [15/Sep/2013:23:56:06, +0100], "GET, /ronin_s4.jpg), Array(104.184.210.93, -, 28402, [15/Sep/2013:23:42:53, +0100], "GET, /titanic_2200.jpg), Array(37.91.137.134, -, 36171, [15/Sep/2013:23:39:33, +0100], "GET, /ronin_novelty_note_3.jpg) ) I need the results to be:

217.150.149.167
104.184.210.93
37.91.137.134

Thanks, Rachel

1 Answer 1

1

Is it okay if your final collection is an Array? You can try:

res21.flatMap(_.headOption) // headOption to be safe and flatMap to flatten the collection
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.