List只是一组有序的对象。dart:core库提供了List类,可以创建和操作列表。
Dart中的列表可分为 -
- 固定长度列表 - 列表的长度不能在运行时更改。
- 可增长列表 - 列表的长度可以在运行时更改。
示例
下面给出了一个Dart实现List的例子。
void main() { 
   List logTypes = new List(); 
   logTypes.add("WARNING"); 
   logTypes.add("ERROR"); 
   logTypes.add("INFO");  
   // iterating across list 
   for(String type in logTypes){ 
      print(type); 
   } 
   // printing size of the list 
   print(logTypes.length); 
   logTypes.remove("WARNING"); 
   print("size after removing."); 
   print(logTypes.length); 
}
执行上面示例代码,得到以下结果 -
WARNING 
ERROR 
INFO 
3 
size after removing. 
2
