dart

Flutter List数组避免插入重复数据

不打扰是莪最后的温柔 提交于 2020-10-01 19:13:20
志当存高远。——诸葛亮 List 具有一定长度存在索引的对象集合(长度为0不存在索引,长度>0存在索引) 常见列表 1、定长列表 默认值null 例如:List<int> fixedLengthList = new List(2)、List<int> fixedLengthList = new List(8) List<int> fixedLengthList = new List(2); for(int i=0;i<2;i++){ print("索引为${i}的值${fixedLengthList[i]}"); } I/flutter ( 9251): 索引为0的值null I/flutter ( 9251): 索引为1的值null 固定长度不可修改 List<int> fixedLengthList = new List(2); //改变固定数组长度 fixedLengthList.length=30; Unsupported operation: Cannot change the length of a fixed-length list 大概意思:无法更改固定长度数组的长度 List<int> fixedLengthList = new List(2); ///执行添加数据操作 fixedLengthList.add(0); fixedLengthList.add(1);