Why array in dart named is List?
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?
Ohh, List.filled solved my problem!!!
https://api.dart.dev/stable/2.8.4/dart-core/List/List.filled.html
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.
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'sListinterface.<You can create fixed-length lists using, e.g.,
List.filled. You can currently also useList<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 toList.filled.