operator [] method
The value for the given key
, or null
if key
is not in the map.
Some maps allow null
as a value.
For those maps, a lookup using this operator cannot distinguish between a
key not being in the map, and the key being there with a null
value.
Methods like containsKey or putIfAbsent can be used if the distinction
is important.
Implementation
@override
V? operator [](Object? key) {
if (isEmpty) return null;
final index = _getBucketIndex(key);
final bucket = _buckets[index];
if (bucket != null) {
for (final entry in bucket) {
if (entry.key == key) {
return entry.value;
}
}
}
return null;
}