Dart StringBuffer isEmpty
Syntax & Examples


StringBuffer.isEmpty property

The `isEmpty` property in Dart returns whether the string buffer is empty. It is a constant-time operation that checks if the buffer contains any elements.


Syntax of StringBuffer.isEmpty

The syntax of StringBuffer.isEmpty property is:

 bool isEmpty 

This isEmpty property of StringBuffer returns whether the string buffer is empty. This is a constant-time operation.

Return Type

StringBuffer.isEmpty returns value of type bool.



✐ Examples

1 Check if a string is empty

In this example,

We create a string buffer `buffer` with the value 'Hello'. We use the `isEmpty` property to check if the string buffer is empty.

Dart Program

void main() {
  StringBuffer buffer = StringBuffer('Hello');
  bool isBufferEmpty = buffer.isEmpty;
  print('Is buffer empty: $isBufferEmpty');
}

Output

Is buffer empty: false

2 Check if a string buffer is empty

In this example,

We create a string buffer `buffer` with no initial content. We use the `isEmpty` property to check if the buffer is empty.

Dart Program

void main() {
  StringBuffer buffer = StringBuffer();
  bool isBufferEmpty = buffer.isEmpty;
  print('Is buffer empty: $isBufferEmpty');
}

Output

Is buffer empty: true

Summary

In this Dart tutorial, we learned about isEmpty property of StringBuffer: the syntax and few working examples with output and detailed explanation for each example.