December 2015
Intermediate to advanced
400 pages
13h 3m
English
You have been doing a lot of tinkering with your bucket list array. But you can also create an array that cannot be changed. You use immutable arrays for these cases. Here is how.
Let’s say you are making an application that allows users to keep track of the lunches they eat each week. Among other things, users will log what they ate and generate reports at a later time. You decide to put these meals in an immutable array to generate the reports. After all, it does not make sense to change last week’s lunches after they have been eaten.
Create an immutable array and initialize it with a week’s worth of lunches.
Listing 9.17 An immutable array
... var myronsList = [ "Climb Mt. Kilimanjaro", "Fly hot air balloon ...
Read now
Unlock full access