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