Dart Set isNotEmpty
Syntax & Examples
Set.isNotEmpty property
The `isNotEmpty` property in Dart returns true if there is at least one element in the set.
Syntax of Set.isNotEmpty
The syntax of Set.isNotEmpty property is:
bool isNotEmpty
This isNotEmpty property of Set returns true if there is at least one element in this collection.
Return Type
Set.isNotEmpty returns value of type bool
.
✐ Examples
1 Non-Empty Set of Numbers
In this example,
- We create a Set
numbers
containing some numbers. - We check if the set is not empty using the
isNotEmpty
property. - We print the result to standard output.
Dart Program
void main() {
Set<int> numbers = {1, 2, 3};
bool result = numbers.isNotEmpty;
print('Is the set not empty? $result');
}
Output
Is the set not empty? true
2 Empty Set of Characters
In this example,
- We create an empty Set
characters
. - We check if the set is not empty using the
isNotEmpty
property. - We print the result to standard output.
Dart Program
void main() {
Set<String> characters = {};
bool result = characters.isNotEmpty;
print('Is the set not empty? $result');
}
Output
Is the set not empty? false
3 Non-Empty Set of Strings
In this example,
- We create a Set
strings
containing some strings. - We check if the set is not empty using the
isNotEmpty
property. - We print the result to standard output.
Dart Program
void main() {
Set<String> strings = {'apple', 'banana', 'orange'};
bool result = strings.isNotEmpty;
print('Is the set not empty? $result');
}
Output
Is the set not empty? true
Summary
In this Dart tutorial, we learned about isNotEmpty property of Set: the syntax and few working examples with output and detailed explanation for each example.