Sdk: why array in dart named is List?

Created on 21 Jul 2020  路  5Comments  路  Source: dart-lang/sdk

Why array in dart named is List?

type-question

Most helpful comment

@julemand101 is correct. Dart decided early on to only have one List-like interface, not one for fixed length lists, one for immutable lists and one for growable lists. Therefore the interface contains all the methods of a growable list, and the interface is named similarly to Java's List interface.<

You can create fixed-length lists using, e.g., List.filled. You can currently also use List<int>(8) to make a fixed-length list of length 8, but that constructor will stop working when we introduce null safety, so get used to List.filled.

All 5 comments

I am not a designer of the language or developer but my guess is the reason is that the Dart List does have similar properties to the List class in C# and List interface in Java implemented by ArrayList. A List in Dart is per default able to change size when elements are added and removed.

When calling something Array I usually think it is a fixed sized list of elements like arrays in Java.

@julemand101 But if I need a Array with constant length I need use List everywhere?

Yes, there are multiple ways to create fixed-length lists in Dart which are locked in size. One of them is List.filled. Take a look at the others here: https://api.dart.dev/stable/2.8.4/dart-core/List-class.html#constructors

@julemand101 is correct. Dart decided early on to only have one List-like interface, not one for fixed length lists, one for immutable lists and one for growable lists. Therefore the interface contains all the methods of a growable list, and the interface is named similarly to Java's List interface.<

You can create fixed-length lists using, e.g., List.filled. You can currently also use List<int>(8) to make a fixed-length list of length 8, but that constructor will stop working when we introduce null safety, so get used to List.filled.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranquild picture ranquild  路  3Comments

DartBot picture DartBot  路  3Comments

brooth picture brooth  路  3Comments

nex3 picture nex3  路  3Comments

55555Mohit55555 picture 55555Mohit55555  路  3Comments