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

ParameterOptional/RequiredDescription
countrequiredThe 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,

  1. We create a list numbers containing integers.
  2. We use the skip() method to skip the first 2 elements.
  3. 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,

  1. We create a list words containing strings.
  2. We use the skip() method to skip the first element.
  3. 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,

  1. We create a set uniqueNumbers containing integers.
  2. We use the skip() method to skip the first element.
  3. 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.