AppDividend
Latest Code Tutorials

Dart List Example | Dart Programming List Tutorial

0

Dart List Example | Dart Programming List Tutorial is today’s topic. The Dart List is the ordered group of objects. The dart: core library provides a List class that enables the creation and manipulation of lists. The very commonly used collection in programming is an array. Dart represents the arrays in the form of List objects. A unique number called the index identifies each element in the List. An index starts from zero and extends up to n-1 where n is a total number of items in the List.

Dart List Example

Lists can be classified into two types.

  • Fixed Length List
  • Growable List

Fixed Length List

A fixed-length list’s length cannot change at runtime. Syntax for creating the fixed length list is as given below.

var list_name = new List(initial_size)

Let’s see the following example.

// app.dart

void main() {
  var initial_size = 5;
  var app_list = new List(initial_size);
  app_list[0] = 'Krunal';
  app_list[1] = 'Ankit';
  app_list[2] = 'Rushabh';
  app_list[3] = 'Dhaval';
  app_list[4] = 'Nehal';

  print(app_list);
}

Let’s see the output inside the terminal.

 

Dart List Example | Dart Programming List Tutorial

Growable List

The growable list’s length can change at the run-time. Syntax for declaring and initializing a growable list is as given below.

var list_name = new List()

Let’s see the following example.

// app.dart

void main() {
  var app_list = [19, 21, 46];
  print(app_list);
}

The output is following.

 

Dart Programming List Tutorial

We can check the length of List using the length function.

// app.dart

void main() {
  var app_list = [19, 21, 46];
  print(app_list.length);
}

The output is following.

 

Fixed Length List Example

Dart List Properties

We have seen one List property called length. Some other properties of List are following.

First

This property returns the first element in the list.

// app.dart

void main() {
  var app_list = [19, 21, 46];
  print(app_list.first);
}

The output is following.

 

Dart List First property

You can find more properties on official documentation.

Finally, Dart List Example | Dart Programming List Tutorial is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.