contains method
Whether the collection contains an element equal to element
.
This operation will check each element in order for being equal to element
, unless it has a more efficient way to find an element equal to element
.
The equality used to determine whether element
is equal to an element of the Iterable defaults to the Object.== of the element.
Some types of Iterable may have a different equality used for its elements.
For example, a Set may have a custom equality (see Set.identity) that its contains
uses.
Likewise the Iterable
returned by a Map.keys call should use the same equality that the Map
uses for keys.
コレクションに element
と等しい要素が含まれているかどうかを調べます。
この操作は、element
と等しい要素を見つけるためのより効率的な方法がない限り、各要素が element
と等しいかどうかを順番にチェックします。
element
が Iterable の要素と等しいかどうかを判断するために使用される等価性は、デフォルトで要素の Object.== になります。
一部のタイプの Iterable では、要素に使用される等価性が異なる場合があります。
たとえば、Set には、その contains
が使用するカスタムの等価性 (Set.identity を参照) がある場合があります。
同様に、Map.keys 呼び出しによって返される Iterable
は、Map
がキーに使用するのと同じ等価性を使用する必要があります。
Example:
final gasPlanets = <int, String>{1: 'Jupiter', 2: 'Saturn'};
final containsOne = gasPlanets.keys.contains(1); // true
final containsFive = gasPlanets.keys.contains(5); // false
final containsJupiter = gasPlanets.values.contains('Jupiter'); // true
final containsMercury = gasPlanets.values.contains('Mercury'); // false
Returns false
if itself is Null.
自身がNullな場合はfalse
を返します。
Implementation
bool contains(Object? element) {
if (this == null) {
return false;
}
return this!.contains(element);
}