The syntax of String.isEmpty property is:
bool isEmpty
This isEmpty property of String checks whether this string is empty.
String.isEmpty returns value of type bool
.
In this example,
str1
.isEmpty
property of str1
to check if it is empty.str1
is empty, the isEmpty
property returns true
.void main() {
String str1 = ''; // empty string
bool isEmpty1 = str1.isEmpty;
print('Is str1 empty: $isEmpty1');
}
Is str1 empty: true
In this example,
str2
with the value 'ABC'.isEmpty
property of str2
to check if it is empty.str2
is not empty, the isEmpty
property returns false
.void main() {
String str2 = 'ABC'; // non-empty string
bool isEmpty2 = str2.isEmpty;
print('Is str2 empty: $isEmpty2');
}
Is str2 empty: false
In this example,
str3
.isEmpty
property of str3
to check if it is empty.str3
is empty, the isEmpty
property returns true
.void main() {
String str3 = ''; // empty string
bool isEmpty3 = str3.isEmpty;
print('Is str3 empty: $isEmpty3');
}
Is str3 empty: true
In this Dart tutorial, we learned about isEmpty property of String: the syntax and few working examples with output and detailed explanation for each example.