如果以格式Array[(Int, (Array[String], Int))]
格式输入数据,则必须映射数组并提取所需的信息。
你的数据结构看起来像
Tuple(integer, Tuple(Array, integer)))
| | | |
| | | |
_1 _2 | |
_2._1 _2._2
例如,
scala> val data = Array((27120,(Array("27120", "2011-12-01 09:59:17.0", "2013-09-07 08:29:37.0", "Dale, Hanson", "2578 Ingram Road, Inglewood, CA, 90309"),8)),
(92694,(Array("92694", "2013-01-25 04:11:10.0", "2013-12-04 02:31:35.0", "Stacy, Allbritton", "4990 Clearview Drive, Sacramento, CA, 94215"),2)),
(40581,(Array("40581", "2012-04-03 17:53:32.0", "2013-12-10 22:46:16.0", "Norman, Scanlon", "312 Ocala Street, Sacramento, CA, 95761"),2)))
data: Array[(Int, (Array[String], Int))] = Array((27120,(Array(27120, 2011-12-01 09:59:17.0, 2013-09-07 08:29:37.0, Dale, Hanson, 2578 Ingram Road, Inglewood, CA, 90309),8)), (92694,(Array(92694, 2013-01-25 04:11:10.0, 2013-12-04 02:31:35.0, Stacy, Allbritton, 4990 Clearview Drive, Sacramento, CA, 94215),2)), (40581,(Array(40581, 2012-04-03 17:53:32.0, 2013-12-10 22:46:16.0, Norman, Scanlon, 312 Ocala Street, Sacramento, CA, 95761),2)))
scala> data.map(tuple => (tuple._1, tuple._2._2, tuple._2._1(3)))
res20: Array[(Int, Int, String)] = Array((27120,8,Dale, Hanson), (92694,2,Stacy, Allbritton), (40581,2,Norman, Scanlon))
你尝试过什么?你有什么问题? –
只需将该元组数组存储在变量中,例如。 val userData。 userData.foreach(entry => {println(entry._1 +“”+ entry._2._2 +“”+ entry._2._1(3)+“”+ entry._2._1(4)) }) –
谢谢!这很棒。我现在明白如何索引元组... – Rachel