The syntax of List.skip() method is:
Iterable<E> skip(int count)
This skip() method of List creates an Iterable
that provides all but the first count
elements.
Parameter | Optional/Required | Description |
---|---|---|
count | required | the number of elements to skip |
List.skip() returns value of type Iterable<E>
.
In this example,
numbers
containing the integers [1, 2, 3, 4, 5]
.skip()
method to skip the first 2 elements of the list.void main() {
List<int> numbers = [1, 2, 3, 4, 5];
Iterable<int> skippedNumbers = numbers.skip(2);
print(skippedNumbers);
}
(3, 4, 5)
In this example,
characters
containing the characters ['a', 'b', 'c', 'd']
.skip()
method to skip the first element of the list.void main() {
List<String> characters = ['a', 'b', 'c', 'd'];
Iterable<String> skippedCharacters = characters.skip(1);
print(skippedCharacters);
}
(b, c, d)
In this example,
words
containing the strings ['apple', 'banana', 'cherry', 'date']
.skip()
method to skip the first 3 elements of the list.void main() {
List<String> words = ['apple', 'banana', 'cherry', 'date'];
Iterable<String> skippedWords = words.skip(3);
print(skippedWords);
}
(date)
In this Dart tutorial, we learned about skip() method of List: the syntax and few working examples with output and detailed explanation for each example.