Dart String isNotEmpty
Syntax & Examples

Syntax of String.isNotEmpty

The syntax of String.isNotEmpty property is:

 bool isNotEmpty 

This isNotEmpty property of String checks whether this string is not empty.

Return Type

String.isNotEmpty returns value of type bool.



✐ Examples

1 Check if a non-empty string is not empty

In this example,

  1. We create a string str with the value 'Hello'.
  2. We then access the isNotEmpty property of the string.
  3. Since the string is not empty, the property returns true.
  4. We print the result to standard output.

Dart Program

void main() {
  String str = 'Hello';
  bool notEmpty = str.isNotEmpty;
  print('Is $str not empty: $notEmpty');
}

Output

Is Hello not empty: true

2 Check if another non-empty string is not empty

In this example,

  1. We create a string str with the value 'ABCDEF'.
  2. We then access the isNotEmpty property of the string.
  3. Since the string is not empty, the property returns true.
  4. We print the result to standard output.

Dart Program

void main() {
  String str = 'ABCDEF';
  bool notEmpty = str.isNotEmpty;
  print('Is $str not empty: $notEmpty');
}

Output

Is ABCDEF not empty: true

3 Check if an empty string is not empty

In this example,

  1. We create a string str with the value '' (empty string).
  2. We then access the isNotEmpty property of the string.
  3. Since the string is empty, the property returns false.
  4. We print the result to standard output.

Dart Program

void main() {
  String str = ''; // Empty string
  bool notEmpty = str.isNotEmpty;
  print('Is $str not empty: $notEmpty');
}

Output

Is  not empty: false

Summary

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