arrays - Storing values obtained from for each loop Scala -
scala beginner trying store values obtains in scala foreach loop failing miserably. basic foreach loop looks currently:
order.orderlist.foreach((x: orderref) => { val references = x.ref}))
when run foreach loop execute twice , return reference each time. i'm trying capture reference value returns on each run (so 2 references in either list or array form can access these values later)
i'm confused how go doing this...
i attempted retrieve , store values array when ran, array list doesn't seem hold values.
this attempt:
val newarray = array(order.orderlist.foreach((x: orderref) => { val references = x.ref })) println(newarray)
any advice appreciated. if there better way achieve this, please share. thanks
use map
instead of foreach
order.orderlist.map((x: orderref) => {x.ref}))
also val references = x.ref
doesn't return anything. create new local variable , assign value it.
Comments
Post a Comment