请帮助我,
我有一个带有字符串类型的多列表:
List<List<String>> mergedList = [["39", "Green"], ["40", "Blue"], ["39", "Blue"], ["40", "Green"]]
我想像这样使用indexOf来找到[“ 39”,“ Green”]的索引:
mergedList.indexOf(["39","Green"])
但是它总是返回-1。
请帮助我在哪里做错了
答案 0 :(得分:0)
就您而言,您可以使用indexWhere
并与element.toString()
进行比较
完整代码
void main() {
List<List<String>> mergedList = [["39", "Green"], ["40", "Blue"], ["39", "Blue"], ["40", "Green"]];
var pos = mergedList.indexWhere((element) => element.toString() == ["39","Green"].toString());
print(pos);
var pos1 = mergedList.indexWhere((element) => element.toString() == ["39","Blue"].toString());
print(pos1);
}
输出
0
2
工作演示