To check if a Set is not empty in Dart, you can use the isEmpty
property.
In this example,
set
and initialize it with some elements.isEmpty
property on the Set set
to check if it contains any elements.isEmpty
property returns false
; otherwise, it returns true
.void main() {
Set<int> set = {1, 2, 3}; // Or Set<int> set = {} for an empty Set
if (!set.isEmpty) {
print('The Set is not empty');
} else {
print('The Set is empty');
}
}
The Set is not empty
In this example,
emptySet
.isEmpty
property on the Set emptySet
to check if it contains any elements.isEmpty
property returns true
.void main() {
Set<int> emptySet = {};
if (!emptySet.isEmpty) {
print('The Set is not empty');
} else {
print('The Set is empty');
}
}
The Set is empty
In this tutorial, we learned How to check if a Set is Not Empty in Dart language with well detailed examples.