Reputation: 1280
I have several values that i am reading from simple Text file
.
This is my data:
val data = new ListBuffer[(String, BigDecimal)]
Now i want to append items inside my ListBuffer
:
data += ("bla bla", 12)
And then error received:
type mismatch; found : List[(String, scala.math.BigDecimal)] required: (String, BigDecimal) data += List(("bla bla", 12))
Upvotes: 2
Views: 2258
Reputation: 4256
To append it as tuple you should enclose it in parenthesis like this:
data += (("bla bla", 12))
Or you could use append
method.
Upvotes: 5
Reputation: 689
You can use the append
function to achive this, e.g.
scala> val data = new ListBuffer[(String, BigDecimal)]
data: scala.collection.mutable.ListBuffer[(String, BigDecimal)] = ListBuffer()
scala> data.append(("bla bla", 12))
scala> data
res11: scala.collection.mutable.ListBuffer[(String, BigDecimal)] = ListBuffer((bla bla,12))
Upvotes: 1