Foreach vs Map in Scala

Viewed 8162

i tried two ways for making a list out of something

var response = List[RS_TxnNested]
consumertxnlist.foreach(txData => {
  response = RS_TxnNested(blabla) +: response
})

where consumertxnlist is a Seq[something] .

Another way is

var response = consumerTxnList._2.map(txData => RS_TxnNested(blabla))

Can someone help me in clarifying which one is better and why?

5 Answers
Related