Dart Tutorials

Dart List.empty()
Syntax & Examples

Syntax of List.empty

The syntax of List.List.empty constructor is:

List.empty({bool growable = false})

This List.empty constructor of List creates a new empty list.

Parameters

ParameterOptional/RequiredDescription
growableoptional [default value is false]whether the list is growable


✐ Examples

1 Create an empty list of numbers

In this example,

  1. We create an empty list named numbers by calling List.empty().
  2. Since no arguments are provided, the list is not growable by default.
  3. We print the list to standard output.

Dart Program

void main() {
  List<int> numbers = List.empty();
  print(numbers); // Output: []
}

Output

[]

2 Create an empty list of characters with growable set to true

In this example,

  1. We create an empty list named characters by calling List.empty(growable: true).
  2. We explicitly set growable parameter to true, making the list growable.
  3. We print the list to standard output.

Dart Program

void main() {
  List<String> characters = List.empty(growable: true);
  print(characters); // Output: []
}

Output

[]

3 Create an empty list of strings

In this example,

  1. We create an empty list named strings by calling List.empty().
  2. Since no arguments are provided, the list is not growable by default.
  3. We print the list to standard output.

Dart Program

void main() {
  List<String> strings = List.empty();
  print(strings); // Output: []
}

Output

[]

Summary

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