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

Course Content

Introduction to Dart

IndexesIndexes

About Indexes

Every element in the List, or String, has a unique address. Such addresses are called indexes:

Indexes start from 0. The first element is assigned the index 0, the second element is assigned the index 1, and so on.

We can retrieve an element from the list using its index with the following syntax:

Example

Let's print the element at index 1 from the List:

dart

main.dart

Editing

Dart allows modifying the value of an item in a List. In other words, one can re-write the value of a List item.

dart

main.dart

The above example updates the value of the List item with index 0. The output of the code will be − [‘Toyota’, ‘Porsche’, ‘Ford’]

String Indexes

In a String, we also have indexes.

dart

main.dart

Note

The only difference between Indexes in a String and Indexes in a List is that in Lists, we can update values at those addresses, whereas in Strings, we cannot.

Task

Select the element at index 1 in the string 'Codefinity'.

Select the correct answer

Everything was clear?

Section 4. Chapter 2
course content

Course Content

Introduction to Dart

IndexesIndexes

About Indexes

Every element in the List, or String, has a unique address. Such addresses are called indexes:

Indexes start from 0. The first element is assigned the index 0, the second element is assigned the index 1, and so on.

We can retrieve an element from the list using its index with the following syntax:

Example

Let's print the element at index 1 from the List:

dart

main.dart

Editing

Dart allows modifying the value of an item in a List. In other words, one can re-write the value of a List item.

dart

main.dart

The above example updates the value of the List item with index 0. The output of the code will be − [‘Toyota’, ‘Porsche’, ‘Ford’]

String Indexes

In a String, we also have indexes.

dart

main.dart

Note

The only difference between Indexes in a String and Indexes in a List is that in Lists, we can update values at those addresses, whereas in Strings, we cannot.

Task

Select the element at index 1 in the string 'Codefinity'.

Select the correct answer

Everything was clear?

Section 4. Chapter 2
some-alt