Dart Tutorials

Dart List skip()
Syntax & Examples

Syntax of List.skip()

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.

Parameters

ParameterOptional/RequiredDescription
countrequiredthe number of elements to skip

Return Type

List.skip() returns value of type Iterable<E>.



✐ Examples

1 Skip elements in a list of numbers

In this example,

  1. We create a list named numbers containing the integers [1, 2, 3, 4, 5].
  2. We then use the skip() method to skip the first 2 elements of the list.
  3. We print the resulting iterable to standard output.

Dart Program

void main() {
  List&lt;int&gt; numbers = [1, 2, 3, 4, 5];
  Iterable&lt;int&gt; skippedNumbers = numbers.skip(2);
  print(skippedNumbers);
}

Output

(3, 4, 5)

2 Skip elements in a list of characters

In this example,

  1. We create a list named characters containing the characters ['a', 'b', 'c', 'd'].
  2. We then use the skip() method to skip the first element of the list.
  3. We print the resulting iterable to standard output.

Dart Program

void main() {
  List&lt;String&gt; characters = ['a', 'b', 'c', 'd'];
  Iterable&lt;String&gt; skippedCharacters = characters.skip(1);
  print(skippedCharacters);
}

Output

(b, c, d)

3 Skip elements in a list of words

In this example,

  1. We create a list named words containing the strings ['apple', 'banana', 'cherry', 'date'].
  2. We then use the skip() method to skip the first 3 elements of the list.
  3. We print the resulting iterable to standard output.

Dart Program

void main() {
  List&lt;String&gt; words = ['apple', 'banana', 'cherry', 'date'];
  Iterable&lt;String&gt; skippedWords = words.skip(3);
  print(skippedWords);
}

Output

(date)

Summary

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.