Dart Runes skip()
Syntax & Examples
Runes.skip() method
The `skip` method in Dart returns an Iterable that provides all but the first count elements.
Syntax of Runes.skip()
The syntax of Runes.skip() method is:
Iterable<int> skip(int count)
This skip() method of Runes returns an Iterable that provides all but the first count
elements.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
count | required | The number of elements to skip from the beginning of the Iterable. |
Return Type
Runes.skip() returns value of type Iterable<int>
.
✐ Examples
1 Skipping elements from a list of numbers
In this example,
- We create a list
numbers
containing integers. - We use the
skip()
method to skip the first 2 elements. - We convert the resulting Iterable to a list and print it.
Dart Program
void main() {
List<int> numbers = [1, 2, 3, 4, 5];
Iterable<int> skipped = numbers.skip(2);
print(skipped.toList());
}
Output
[3, 4, 5]
2 Skipping elements from a list of strings
In this example,
- We create a list
words
containing strings. - We use the
skip()
method to skip the first element. - We convert the resulting Iterable to a list and print it.
Dart Program
void main() {
List<String> words = ['apple', 'banana', 'cherry'];
Iterable<String> skipped = words.skip(1);
print(skipped.toList());
}
Output
[banana, cherry]
3 Skipping elements from a set of numbers
In this example,
- We create a set
uniqueNumbers
containing integers. - We use the
skip()
method to skip the first element. - We convert the resulting Iterable to a list and print it.
Dart Program
void main() {
Set<int> uniqueNumbers = {1, 2, 3};
Iterable<int> skipped = uniqueNumbers.skip(1);
print(skipped.toList());
}
Output
[2, 3]
Summary
In this Dart tutorial, we learned about skip() method of Runes: the syntax and few working examples with output and detailed explanation for each example.