目录

List

List只是一组有序的对象。 dart:core库提供了List类,可以创建和操作列表。

Dart中的列表可归类为 -

  • Fixed Length List - 列表的长度在运行时不能更改。

  • Growable List - 列表的长度可以在运行时更改。

例子 (Example)

下面给出了一个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); 
}

上述代码的output如下 -

WARNING 
ERROR 
INFO 
3 
size after removing. 
2
↑回到顶部↑
WIKI教程 @2018