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

Note
Definition

A List in Dart is a built-in data type that represents an ordered collection of elements. Each element in a List usually has the same data type, such as integers, floating-point numbers, strings, or other objects.

Lists are useful for:

  • Storing data about a group of related items, such as a shopping list, to-do list, or contact list.
  • Tracking sequences of events, such as a history log or a list of steps needed to complete a task.

They help keep related information organized and easy to access.

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.
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);

The expression numbers.add(6); calls the add() method on the variable numbers, adding the value 6 to it.

Deleting Items

list_name.remove(element)

The expression list_name.remove(element) calls the remove() method on the variable, deleting the first occurrence of the specified value.

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] }
question mark

Which method should you use to add a new element to the end of a List in Dart?

Select the correct answer

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

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

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

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

Запитати АІ

expand

Запитати АІ

ChatGPT

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

Awesome!

Completion rate improved to 4.55

bookList in Dart

Свайпніть щоб показати меню

Note
Definition

A List in Dart is a built-in data type that represents an ordered collection of elements. Each element in a List usually has the same data type, such as integers, floating-point numbers, strings, or other objects.

Lists are useful for:

  • Storing data about a group of related items, such as a shopping list, to-do list, or contact list.
  • Tracking sequences of events, such as a history log or a list of steps needed to complete a task.

They help keep related information organized and easy to access.

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.
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);

The expression numbers.add(6); calls the add() method on the variable numbers, adding the value 6 to it.

Deleting Items

list_name.remove(element)

The expression list_name.remove(element) calls the remove() method on the variable, deleting the first occurrence of the specified value.

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] }
question mark

Which method should you use to add a new element to the end of a List in Dart?

Select the correct answer

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

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

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

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