bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java LinkedList spliterator() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java LinkedList spliterator() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Order

Put the learning moves in the order that makes the concept easiest to apply.

The spliterator() method returns a Spliterator for the list.
Definition and Usage
Java LinkedList spliterator() Method

❮ LinkedList Methods

Spliterator

Note

The syntax while( it1.tryAdvance( (n) -> { System.out.println(n); } ) ); is equivalent to:

boolean x = it1.tryAdvance( (n) -> { System.out.println(n); });
while(x) {
 x = it1.tryAdvance( (n) -> { System.out.println(n); });
}

Definition and Usage

The spliterator() method returns a Spliterator for the list.

A spliterator is a special type of iterator. To learn how to use iterators, see our Java Iterator tutorial .

The Spliterator is considerably different from an ordinary iterator. The purpose of a spliterator is to separate a collection into smaller pieces so that each piece can be processed by a separate thread. The Spliterator interface has two important methods:

  • trySplit() - Returns a new spliterator which can iterate through (usually and approximately) half of the elements that the original spliterator has access to, while the original spliterator can iterate through the remaining half.
  • tryAdvance(Consumer action ) - Moves to the next item that is available to the spliterator and tries to perform an action on it. If there is no next item then it returns false . The action can be defined by a lambda expression.

Syntax

public Spliterator spliterator()

Technical Details

Returns:A Spliterator object.
Java version:1.8+

Previous

Java LinkedList sort() Method

Next

Java LinkedList subList() Method