listscalalistbuffer

Append ListBuffer with tuple


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))


Solution

  • To append it as tuple you should enclose it in parenthesis like this:

    data += (("bla bla", 12))
    

    Or you could use append method.