Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dgadiraju/964ce27ea1bf8eafa358d29ca32f7bbd to your computer and use it in GitHub Desktop.

Select an option

Save dgadiraju/964ce27ea1bf8eafa358d29ca32f7bbd to your computer and use it in GitHub Desktop.
val m = Map(
(1, Order(1, "2017-01-01", 100, "COMPLETE")),
(2, Order(2, "2017-01-01", 20, "CLOSED"))
)
//as m is immutable we cannot use +=, ++=, -= and --=
m + ((3, Order(3, "2017-01-01", 301, "PENDING")))
m + (3 -> Order(3, "2017-01-01", 301, "PENDING"))
//let us define m as mutable Map
val m = collection.mutable.Map(
(1, Order(1, "2017-01-01", 100, "COMPLETE")),
(2, Order(2, "2017-01-01", 20, "CLOSED"))
)
//Now we can manipulate map by using +=, ++=, -=, --=
m += ((3, Order(3, "2017-01-01", 301, "PENDING")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment