The `take` method in Dart returns a lazy iterable of the count first elements of this iterable.
The syntax of Runes.take() method is:
Iterable<int> take(int count)
This take() method of Runes returns a lazy iterable of the count
first elements of this iterable.
Parameter | Optional/Required | Description |
---|---|---|
count | required | The number of elements to take from the beginning of the iterable. |
Runes.take() returns value of type Iterable<int>
.
In this example,
numbers
containing integers.take()
method to take the first 3 elements.void main() {
List<int> numbers = [1, 2, 3, 4, 5];
Iterable<int> taken = numbers.take(3);
print(taken.toList());
}
[1, 2, 3]
In this example,
words
containing strings.take()
method to take the first 2 elements.void main() {
List<String> words = ['apple', 'banana', 'cherry'];
Iterable<String> taken = words.take(2);
print(taken.toList());
}
[apple, banana]
In this example,
uniqueNumbers
containing integers.take()
method to take the first element.void main() {
Set<int> uniqueNumbers = {1, 2, 3};
Iterable<int> taken = uniqueNumbers.take(1);
print(taken.toList());
}
[1]
In this Dart tutorial, we learned about take() method of Runes: the syntax and few working examples with output and detailed explanation for each example.