我是Scala新手,可能需要一些帮助。我有一个RDD,即Array[ArrayString]。我需要提取每个内部数组中的第一个元素。样本记录如下:
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) )我需要的结果是:
217.150.149.167
104.184.210.93
37.91.137.134谢谢你,瑞秋
发布于 2017-10-10 17:59:31
如果您的最后集合是Array,可以吗?你可以试试:
res21.flatMap(_.headOption) // headOption to be safe and flatMap to flatten the collectionhttps://stackoverflow.com/questions/46673027
复制相似问题