The `whereType` method in Dart returns a new lazy Iterable with all elements that have type T.
The syntax of Runes.whereType() method is:
Iterable<T> whereType<T>()
This whereType() method of Runes returns a new lazy Iterable with all elements that have type T
.
Runes.whereType() returns value of type Iterable<T>
.
In this example,
mixedList
containing elements of various types.whereType()
method with type int
to filter integers.void main() {
List<dynamic> mixedList = [1, 'apple', true, 2.5, 'banana'];
Iterable<int> integers = mixedList.whereType<int>();
print(integers.toList());
}
[1]
In this example,
mixedList
containing elements of various types.whereType()
method with type String
to filter strings.void main() {
List<dynamic> mixedList = [1, 'apple', true, 2.5, 'banana'];
Iterable<String> strings = mixedList.whereType<String>();
print(strings.toList());
}
[apple, banana]
In this example,
mixedSet
containing elements of various types.whereType()
method with type int
to filter integers.void main() {
Set<dynamic> mixedSet = {1, 'apple', true};
Iterable<int> integers = mixedSet.whereType<int>();
print(integers.toList());
}
[1]
In this Dart tutorial, we learned about whereType() method of Runes: the syntax and few working examples with output and detailed explanation for each example.