Our first program will demonstrate how to work with arrays in Dart. Here’s the full source code with explanations:
To run the program, save it as arrays.dart and use the dart command:
Note that Lists in Dart are displayed in the form [v1, v2, v3, ...] when printed.
In Dart, we use Lists instead of arrays. Lists are more flexible and can be resized dynamically. The List<int> syntax specifies a List that contains integers.
Dart doesn’t have a direct equivalent to Go’s [...]int{1, 2, 3} syntax for creating arrays with inferred length. Instead, we can simply use [1, 2, 3] to create a List.
For creating Lists with specific indexes filled and others empty, we use List.generate constructor instead of Go’s index specification syntax.
Multi-dimensional data structures in Dart are created using Lists of Lists, similar to how it’s done in many other languages.