Dart Set skip()
Syntax & Examples


Set.skip() method

The `skip` method in Dart returns an iterable that provides all elements except the first specified number of elements.


Syntax of Set.skip()

The syntax of Set.skip() method is:

 Iterable<E> skip(int count) 

This skip() method of Set 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

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



✐ Examples

1 Skipping elements from a list of numbers

In this example,

  1. We create an Iterable numbers with values [1, 2, 3, 4, 5].
  2. We use the skip() method with a count of 2 to skip the first two elements.
  3. We print the result, which contains elements starting from the third element.

Dart Program

void main() {
  Iterable<int> numbers = [1, 2, 3, 4, 5];
  Iterable<int> skippedNumbers = numbers.skip(2);
  print(skippedNumbers); // Output: (3, 4, 5)
}

Output

(3, 4, 5)

2 Skipping elements from a list of strings

In this example,

  1. We create an Iterable words with values ['apple', 'banana', 'cherry'].
  2. We use the skip() method with a count of 1 to skip the first element.
  3. We print the result, which contains elements starting from the second element.

Dart Program

void main() {
  Iterable<String> words = ['apple', 'banana', 'cherry'];
  Iterable<String> skippedWords = words.skip(1);
  print(skippedWords); // Output: (banana, cherry)
}

Output

(banana, cherry)

Summary

In this Dart tutorial, we learned about skip() method of Set: the syntax and few working examples with output and detailed explanation for each example.