Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
List | List and String
Introduction to Dart

ListList

About List

A List in the Dart programming language is an inherent data type that represents an ordered collection of elements. Each element within a List should typically have the same data type, whether it's integers, floating-point numbers, strings, or other objects.

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 - 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 1

Example of creating a List with int values:

dart

main.dart

  • List of integer numbers;
  • <int> type elements from List.

Example 2

Frequently, we initialize an empty List with the intention of populating it with data that we will acquire at a later point, such as input from a user.

dart

main.dart

An empty List for bool values was created above.

Adding Items

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

dart

main.dart

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

The remove() function removes the first occurrence of the specified item in the list.

dart

main.dart

We removed 22 from the List

Task

We heva a List

question-icon

Remove the value true from the List items

.;

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

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

Секція 4. Розділ 1
course content

Зміст курсу

Introduction to Dart

ListList

About List

A List in the Dart programming language is an inherent data type that represents an ordered collection of elements. Each element within a List should typically have the same data type, whether it's integers, floating-point numbers, strings, or other objects.

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 - 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 1

Example of creating a List with int values:

dart

main.dart

  • List of integer numbers;
  • <int> type elements from List.

Example 2

Frequently, we initialize an empty List with the intention of populating it with data that we will acquire at a later point, such as input from a user.

dart

main.dart

An empty List for bool values was created above.

Adding Items

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

dart

main.dart

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

The remove() function removes the first occurrence of the specified item in the list.

dart

main.dart

We removed 22 from the List

Task

We heva a List

question-icon

Remove the value true from the List items

.;

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

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

Секція 4. Розділ 1
some-alt