当前位置 博文首页 > “Allen Su”的博客:【Dart】Dart 之 contains 判断数组中是否
Dart 判断数组中是否含有指定元素,用 contains()
方法,源码定义如下
bool contains(Object element)
该方法的返回值为 bool 类型,参数为 Object 类型。
例
List<String> l1 = ["一月", "二月", "三月","四月"];
bool a = l1.contains("一月");
bool b = l1.contains("八月");
print(a); // true
print(b); // false
如果指定元素在数组中,返回 true,如果不在,返回 false
更多 Dart 中 List 数组的方法,推荐一篇博客 Dart 中 List 数组的常用方法
cs如果这篇博客有幸帮到了您,欢迎点击下方链接,和更多志同道合的伙伴一起交流,一起进步。
结束语