The syntax of List.isEmpty property is:
bool isEmpty
This isEmpty property of List whether this collection has no elements.
List.isEmpty returns value of type bool
.
In this example,
numbers
with elements [1, 2, 3]
.isEmpty
property to check if the list is empty.isEmptyNumbers
.void main() {
List<int> numbers = [1, 2, 3];
bool isEmptyNumbers = numbers.isEmpty;
print('Is numbers empty? $isEmptyNumbers'); // Output: Is numbers empty? false
}
Is numbers empty? false
In this example,
characters
with elements ['a', 'b', 'c']
.isEmpty
property to check if the list is empty.isEmptyCharacters
.void main() {
List<String> characters = ['a', 'b', 'c'];
bool isEmptyCharacters = characters.isEmpty;
print('Is characters empty? $isEmptyCharacters'); // Output: Is characters empty? false
}
Is characters empty? false
In this example,
strings
.isEmpty
property to check if the list is empty.isEmptyStrings
.void main() {
List<String> strings = [];
bool isEmptyStrings = strings.isEmpty;
print('Is strings empty? $isEmptyStrings'); // Output: Is strings empty? true
}
Is strings empty? true
In this Dart tutorial, we learned about isEmpty property of List: the syntax and few working examples with output and detailed explanation for each example.