To check if a Set is empty in Dart, you can use the isEmpty property or the length property.
In this example,
// Define set
Set<String> mySet = {};
// Check if set is empty using isEmpty property
if (mySet.isEmpty) {
print('Set is empty');
} else {
print('Set is not empty');
}
Set is empty
In this example,
// Define set
Set<String> mySet = {};
// Check if set is empty using length property
if (mySet.length == 0) {
print('Set is empty');
} else {
print('Set is not empty');
}
Set is empty
In this example,
// Define non-empty set
Set<String> mySet = {'apple', 'banana', 'orange'};
// Check if set is empty using isEmpty property
if (mySet.isEmpty) {
print('Set is empty');
} else {
print('Set is not empty');
}
Set is not empty
In this example,
// Define non-empty set
Set<String> mySet = {'apple', 'banana', 'orange'};
// Check if set is empty using length property
if (mySet.length == 0) {
print('Set is empty');
} else {
print('Set is not empty');
}
Set is not empty
In this tutorial, we learned How to check if a Set is Empty in Dart language with well detailed examples.