The syntax of List.List.unmodifiable constructor is:
List.unmodifiable(Iterable elements)
This List.unmodifiable constructor of List creates an unmodifiable list containing all elements
.
Parameter | Optional/Required | Description |
---|---|---|
elements | required | the elements to be included in the unmodifiable list |
In this example,
numbers
containing the integers 1, 2, 3
using List.unmodifiable
.numbers
list to standard output.void main() {
List<int> numbers = List.unmodifiable([1, 2, 3]);
print(numbers);
}
[1, 2, 3]
In this example,
characters
containing the characters 'a', 'b', 'c'
using List.unmodifiable
.characters
list to standard output.void main() {
List<String> characters = List.unmodifiable(['a', 'b', 'c']);
print(characters);
}
[a, b, c]
In this example,
words
containing the strings 'apple', 'banana', 'cherry'
using List.unmodifiable
.words
list to standard output.void main() {
List<String> words = List.unmodifiable(['apple', 'banana', 'cherry']);
print(words);
}
[apple, banana, cherry]
In this Dart tutorial, we learned about List.unmodifiable constructor of List: the syntax and few working examples with output and detailed explanation for each example.