數據的陣圖我在斯卡拉一個新手,在這裏我有一個數組變量調用colarr如何從斯卡拉
colarr: Array[(String, String)] = Array((empid,IntegerType), (empname,StringType), (address,StringType), (salary,IntegerType), (doj,TimestampType))
如何獲得個人價值像它EMPID和IntergerType?
數據的陣圖我在斯卡拉一個新手,在這裏我有一個數組變量調用colarr如何從斯卡拉
colarr: Array[(String, String)] = Array((empid,IntegerType), (empname,StringType), (address,StringType), (salary,IntegerType), (doj,TimestampType))
如何獲得個人價值像它EMPID和IntergerType?
如果你想要去在每個元組,你可以使用Array.foreach
:
scala> val arr = Array(("hello", "world"), ("this", "isnice"), ("yay", "it works"))
scala> arr.foreach {
case (first, second) => println(s"First element $first, Second element: $second") }
First element hello, Second element: world
First element this, Second element: isnice
First element yay, Second element: it works
如果你想轉換項目的元組的值,你可以使用Array.map
:
scala> arr.map { case (first, second) => s"$first, $second" }
res1: Array[String] = Array(hello, world, this, isnice, yay, it works)
的case (first, second)
只是用於創建部分函數的語法,它允許您從元組中提取第一個和第二個元素。
scala> arr.map(tuple => s"${tuple._1}, ${tuple._2}")
res2: Array[String] = Array(hello, world, this, isnice, yay, it works)
究竟什麼是你想要做的事:
如果你想對於初學者更簡單的東西,你可以在總功能和與元組的
_.1
和_.2
元素的工作?獲得單一的價值?獲取一些價值?做詳細說明。 –'colarr.toMap.get(empid)'? –
這些是列和表的數據類型,所以我需要得到的值,並檢查其數據類型 – anand