Dart StringBuffer isNotEmpty
Syntax & Examples
StringBuffer.isNotEmpty property
The `isNotEmpty` property in Dart returns whether the buffer is not empty. It is a constant-time operation.
Syntax of StringBuffer.isNotEmpty
The syntax of StringBuffer.isNotEmpty property is:
bool isNotEmpty
This isNotEmpty property of StringBuffer returns whether the buffer is not empty. This is a constant-time operation.
Return Type
StringBuffer.isNotEmpty returns value of type bool
.
✐ Examples
1 Checking if a non-empty StringBuffer is not empty
In this example,
- We create a `StringBuffer` named `buffer` with the content 'Example'.
- We print the value of the `isNotEmpty` property, which should return `true` since the buffer is not empty.
Dart Program
void main() {
StringBuffer buffer = StringBuffer('Example');
print(buffer.isNotEmpty);
}
Output
true
2 Checking if an empty StringBuffer is not empty
In this example,
- We create an empty `StringBuffer` named `emptyBuffer`.
- We print the value of the `isNotEmpty` property, which should return `false` since the buffer is empty.
Dart Program
void main() {
StringBuffer emptyBuffer = StringBuffer();
print(emptyBuffer.isNotEmpty);
}
Output
false
Summary
In this Dart tutorial, we learned about isNotEmpty property of StringBuffer: the syntax and few working examples with output and detailed explanation for each example.