Define 2D array in scala -
i have call function defined foo(seq[seq[int]]) in scala
i have defined int array as:
var myarray = array.ofdim[int](n,n) and calling foo(myarray)
however, getting error:
type mismatch; found : array[array[int]] required: seq[seq[int]] if try define array as
var myarray = seq[seq[int]](n,n) i error:
type mismatch; found : int required: seq[int] why that? struggling more 2 hours, find might problem, have no idea...
can me this?
well, array no subclass of seq, why error.
you can convert array[array[int]] seq[seq[int]] that:
val myarray = array.ofdim[int](n,n) //use vals if can, arrays mutable val myseq = myarray.map(_.toseq).toseq //convert inner arrays seq , outer array seq foo(myseq) keep in mind array mutable, while seq not.
Comments
Post a Comment