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