Page 70 - Touchcode_C7_Flipbook
P. 70
Modification or change in the collection’s elements while iterating or traversing through
that collection is not allowed and it will throw an error.
So, unmodifiable collection are those collections which do not support modification
operations (add, remove and clear). Collections are immutable if there will be no change in
the collection object. Lists are of fixed size, if they assure that their size remains constant
only the elements can change in it. Lists are of variable-size also. You cannot iterate or
modify a null collection.
Adding elements to collection during iteration
To add elements while iterating or traversing a list, set or map, the new elements are kept
in a temporary list, set, or map and then the elements are added once you finish traversing
or iterating the collection.
Removing elements from collection during iteration
To remove elements from a list, you can create a new list, then add or insert the elements you
wish to keep. Or, you can also insert or add the elements you wish to remove to a different
list and then remove the elements after you finish the traversing or iterating the collection.
to remove to a different list and remove them after you finish iterating the collection.
Coding uiz 02 Critical Thinking
Give one-word answer to the following questions.
a. Name the collection which stores similar data type variable. ...........................
b. What is the list called whose size remain constant. ...........................
At a Glance
Collections are used to store data and you can also retrieve and manipulate data stored in
the Collections.
Arrays do not support different data types.
Collections consist of lists, sets, or maps.
Modifying a collection's elements while iterating through that collection is not allowed and
it will throws an error in the program.
To add elements while iterating a list, set or map, keep the new elements in a temporary
list, set, or map and then add them to the original once you finish iterating the collection.
68 Touchcode-VII

