i wanna have a result-Sequence with a Triple of (String, Int, Int) like this:
var all_info: Seq[(String, Int, Int)] = null
now that i try adding elements to my Seq as followed:
if (all_info == null) {
all_info = Seq((name, id, count))
} else {
all_info :+ (name, id, count)
}
and print them
Console.println(all_info.mkString)
Unfortunately, the printed result is only the first triple that is added by the if-clause and basically intializes a new Seq, since it's been just "null" before. All following triples which are supposed to be added to the Seq in the else-clause are not. I also tried different methods like "++" which won't work either ("too many arguments")
Can't really figure out what I'm doing wrong here.
Thanks for any help in advance! Greetings.
First of all instead of using null
s you would be better using an empty collection. Next use :+= so the result of :+ would not be thrown away — :+ produces a new collection as the result instead of modifying the existing one. The final code would look like
var all_info: Seq[(String, Int, Int)] = Seq.empty
all_info :+= (name, id, count)
As you can see, now you don't need if
s and code should work fine.