我怎么知道元组的结构?

时间:2016-04-29 10:07:39

标签: scala tuples

在Scala中的以下元组中:

  

Array [(String,(String,String))] =   阵列((2828,(7097,2828,403,1,129.99,129.99,2828,2013-08-10   00:00:00.0,4952,SUSPECTED_FRAUD)),   (37231,(92926,37231,191,3,299.97,99.99,37231,2014-03-11   00:00:00.0,4470,PENDING)),

您可以看到第二个元组(String,String)包含两个单独的字符串值。但是,我无法通过查看

来确定元组是如何分区的
  

:( 7097,2828,403,1,129.99,129.99,2828,2013-08-10   00:00:00.0,4952,SUSPECTED_FRAUD)

即。我怎么知道哪一个是._2._1值,哪一个是._2._2值?

1 个答案:

答案 0 :(得分:1)

您必须编写自己的打印功能:

val array = Array(("2828",("7097,2828,403,1,129.99,129.99,2828,2013-08-10 00:00:00.0,4952","SUSPECTED_FRAUD")), ("37231",("92926,37231,191,3,299.97,99.99,37231,2014-03-11 00:00:00.0","4470,PENDING")))

array.foreach{case (first, (second, third)) =>
  println(first)
  println(second)
  println(third)
  println("-------------")
}
/*
2828
7097,2828,403,1,129.99,129.99,2828,2013-08-10 00:00:00.0,4952
SUSPECTED_FRAUD
-------------
37231
92926,37231,191,3,299.97,99.99,37231,2014-03-11 00:00:00.0
4470,PENDING
*/