A solution other answers didn't mention: indexOf
.
List<int> values = [2, 3, 4, 5, 6, 7];
print(values.indexOf(5) >= 0); // true, 5 is in values
print(values.indexOf(1) >= 0); // false, 1 is not in values
It also lets you search after an index. With contains
, one would do:
print(values.sublist(3).contains(6)); // true, 6 is after index 3 in values
print(values.sublist(3).contains(2)); // false, 2 is not after index 3 in values
With indexOf
:
print(values.indexOf(6, 3) >= 0); // true, 6 is after index 3 in values
print(values.indexOf(2, 3) >= 0); // false, 2 is not after index 3 in values