Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте List in Dart | Variables and Data Types in Dart
Introduction to Dart

bookList in Dart

Lists can be useful for:

  • Storing data about a list of things, such as a shopping list, a to-do list, or a contact list;
  • Storing data about a sequence of events, such as a history list or a list of steps that need to be taken to complete a task.

Syntax

Let's look at the scheme of creating a List:

List<elements_type> list_name = [element_1, element_2];
  • List: command to create a list;
  • <elements_type>: the data type for values will be stored in the middle of the list;
  • list_name: list name;
  • [element_1, element_2]: commas (,) separate the list elements.

Example

Example of creating a List with int values:

main.dart

main.dart

copy
1
List<int> numbers = [1, 2, 3, 4, 5];
  • List of integer numbers;
  • <int> type elements from List.

Adding Items

Let's add a value to the already existing list of numbers.

main.dart

main.dart

copy
123456
void main() { List<int> numbers = [111, 22, 32]; print(numbers); // Output [111, 22, 32] numbers.add(6); // Adding an item to a list print(numbers); // Output [111, 22, 32, 6] }
numbers.add(6);

Let's break down the new command in detail:

  • numbers: list name;
  • add(): command that adds elements to a list;
  • 6: the value we want to add to the list.

Deleting Items

list_name.remove(element)

Let's break down the new command in detail:

  • numbers: list name;
  • remove(): command that removes the first occurrence of the specified item in the list;
  • element: the value we want to add to the list.
main.dart

main.dart

copy
123456
void main() { List<int> numbers = [11, 22, 23]; print(numbers); // [11, 22, 23] numbers.remove(22); print(numbers); // [11, 23] }

We removed 22 from the List

We heva a List:

List<bool> items = [true, false];
question-icon

Remove the value true from the List items

.;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 6

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookList in Dart

Lists can be useful for:

  • Storing data about a list of things, such as a shopping list, a to-do list, or a contact list;
  • Storing data about a sequence of events, such as a history list or a list of steps that need to be taken to complete a task.

Syntax

Let's look at the scheme of creating a List:

List<elements_type> list_name = [element_1, element_2];
  • List: command to create a list;
  • <elements_type>: the data type for values will be stored in the middle of the list;
  • list_name: list name;
  • [element_1, element_2]: commas (,) separate the list elements.

Example

Example of creating a List with int values:

main.dart

main.dart

copy
1
List<int> numbers = [1, 2, 3, 4, 5];
  • List of integer numbers;
  • <int> type elements from List.

Adding Items

Let's add a value to the already existing list of numbers.

main.dart

main.dart

copy
123456
void main() { List<int> numbers = [111, 22, 32]; print(numbers); // Output [111, 22, 32] numbers.add(6); // Adding an item to a list print(numbers); // Output [111, 22, 32, 6] }
numbers.add(6);

Let's break down the new command in detail:

  • numbers: list name;
  • add(): command that adds elements to a list;
  • 6: the value we want to add to the list.

Deleting Items

list_name.remove(element)

Let's break down the new command in detail:

  • numbers: list name;
  • remove(): command that removes the first occurrence of the specified item in the list;
  • element: the value we want to add to the list.
main.dart

main.dart

copy
123456
void main() { List<int> numbers = [11, 22, 23]; print(numbers); // [11, 22, 23] numbers.remove(22); print(numbers); // [11, 23] }

We removed 22 from the List

We heva a List:

List<bool> items = [true, false];
question-icon

Remove the value true from the List items

.;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 6
some-alt