Dart Runes isNotEmpty
Syntax & Examples

Runes.isNotEmpty property

The `isNotEmpty` property of the `Iterable` class returns true if there is at least one element in the collection, otherwise false.


Syntax of Runes.isNotEmpty

The syntax of Runes.isNotEmpty property is:

 bool isNotEmpty 

This isNotEmpty property of Runes returns true if there is at least one element in this collection.

Return Type

Runes.isNotEmpty returns value of type bool.



✐ Examples

1 Checking if a list of integers is not empty

In this example,

  1. We create a list of integers named numbers.
  2. We use the isNotEmpty property to check if the list has elements.
  3. We then print the result to standard output.

Dart Program

void main() {
  List<int> numbers = [1, 2, 3];
  bool hasElements = numbers.isNotEmpty;
  print('Has Elements: $hasElements'); // Prints: Has Elements: true
}

Output

Has Elements: true

2 Checking if a list of strings is empty

In this example,

  1. We create an empty list of strings named names.
  2. We use the isNotEmpty property to check if the list has elements.
  3. We then print the result to standard output.

Dart Program

void main() {
  List<String> names = [];
  bool hasNames = names.isNotEmpty;
  print('Has Names: $hasNames'); // Prints: Has Names: false
}

Output

Has Names: false

Summary

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