简体   繁体   English

在 dart 中不可能有 Map 个列表吗?

[英]Is Map of lists not possible in dart?

I have data in this order:-我有这个顺序的数据:-

m={ 1:[54,23,98],
    9:[8,4,2]
   }

I'm trying to achieve something like this using the following code but it's not working.我正在尝试使用以下代码实现类似的功能,但它不起作用。 Where am I going wrong?我哪里错了? Is there another way of storing and accessing this type of data in dart if my method is completely wrong?如果我的方法完全错误,是否有另一种方法可以在dart中存储和访问此类数据?

Map<int,List<int>> m;

 m[0]=[];
 m[0].add(5);

You have to initialise it with empty map first你必须先用空的 map 初始化它

  Map<int, List<int>> m={}; //<- initialise it here
  m[0] = [];
  m[0].add(5);
  print(m); // prints {0: [5]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM