Java – Spliterator Interface

Java Spliterator Interface methods, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Variables in Java Spliterator Interface

S.No Variable & Description
1 static int CONCURRENT

Characteristic value signifying that the element source may be safely concurrently modified (allowing additions, replacements, and/or removals) by multiple threads without external synchronization.
2 static int DISTINCT

Characteristic value signifying that, for each pair of encountered elements x, y, !x.equals(y).
3 static int IMMUTABLE

Characteristic value signifying that the element source cannot be structurally modified; that is, elements cannot be added, replaced, or removed, so such changes cannot occur during traversal.
4 static int NONNULL

Characteristic value signifying that the source guarantees that encountered elements will not be null.
5 static int ORDERED

Characteristic value signifying that an encounter order is defined for elements.
6 static int SIZED

Characteristic value signifying that the value returned from estimateSize() prior to traversal or splitting represents a finite size that, in the absence of structural source modification, represents an exact count of the number of elements that would be encountered by a complete traversal.
7 static int SORTED

Characteristic value signifying that encounter order follows a defined sort order.
8 static int SUBSIZED

Characteristic value signifying that all Spliterators resulting from trySplit() will be both SIZED and SUBSIZED.

Methods in Java Spliterator Interface

S.No Method & Description
1 int characteristics()

Returns a set of characteristics of this Spliterator and its elements.
2 long estimateSize()

Returns an estimate of the number of elements that would be encountered by a forEachRemaining(java.util.function.Consumer<? super T>) traversal, or returns Long.MAX_VALUE if infinite, unknown, or too expensive to compute.
3 default void forEachRemaining(Consumer<? super T> action)

Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
4 default Comparator<? super T> getComparator()

If this Spliterator’s source is SORTED by a Comparator, returns that Comparator.
5 default long getExactSizeIfKnown()

Convenience method that returns estimateSize() if this Spliterator is SIZED, else -1.
6 default boolean hasCharacteristics(int characteristics)

Returns true if this Spliterator’s characteristics() contain all of the given characteristics.
7 boolean tryAdvance(Consumer<? super T> action)

If a remaining element exists, performs the given action on it, returning true; else returns false.
8 Spliterator<T> trySplit()

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java – AtomicInteger Class
  2. Java – BiFunction Interface
  3. Java ArrayList ensureCapacity() method with example
  4. How to validate password using Java Regular Expression
  5. Java – ForkJoinTask Class
  6. Java ArrayList forEach() method with example
  7. Java – OptionalInt Class
  8. Java – EnumMap Class
  9. Java – ForkJoinWorkerThread Class
  10. Java – ReentrantReadWriteLock.WriteLock Class
  11. Java ArrayList listIterator() method with example
  12. Java – AbstractSequentialList Class
  13. Java ArrayList removeRange() method with example
  14. Java – AbstractQueuedSynchronizer Class
  15. Java ArrayList add(int index, E element) method with example

Be the first to comment

Leave a Reply