How to define a list of lists in Scala?

前端 未结 5 1312
慢半拍i
慢半拍i 2021-01-11 23:37

I would like to create a storage for the following type:

List(List(2.3,1.1),List(2.2, 1))

But if I do the following:

var y         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-12 00:28

    This seems to have been fixed in Scala 2.9

    Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> var y = List(List (1.0, 2.2), List(2, 1.1, -2.1))
    y: List[List[Double]] = List(List(1.0, 2.2), List(2.0, 1.1, -2.1))
    
    scala> y(0)(0) * 2
    res0: Double = 2.0
    

提交回复
热议问题