Interface IntIterable

All Superinterfaces:
java.lang.Iterable<java.lang.Integer>
All Known Subinterfaces:
IntBidirectionalIterable, IntBigList, IntCollection, IntList, IntSet, IntSortedSet
All Known Implementing Classes:
AbstractIntBigList, AbstractIntBigList.IntRandomAccessSubList, AbstractIntBigList.IntSubList, AbstractIntCollection, AbstractIntList, AbstractIntList.IntRandomAccessSubList, AbstractIntList.IntSubList, AbstractIntSet, AbstractIntSortedSet, IntArrayList, IntArraySet, IntAVLTreeSet, IntBigArrayBigList, IntBigLists.EmptyBigList, IntBigLists.ListBigList, IntBigLists.Singleton, IntBigLists.SynchronizedBigList, IntBigLists.UnmodifiableBigList, IntCollections.EmptyCollection, IntCollections.IterableCollection, IntImmutableList, IntLinkedOpenCustomHashSet, IntLinkedOpenHashSet, IntLists.EmptyList, IntLists.Singleton, IntLists.SynchronizedList, IntLists.SynchronizedRandomAccessList, IntLists.UnmodifiableList, IntLists.UnmodifiableRandomAccessList, IntOpenCustomHashSet, IntOpenHashBigSet, IntOpenHashSet, IntRBTreeSet, IntSets.EmptySet, IntSets.Singleton, IntSets.SynchronizedSet, IntSets.UnmodifiableSet, IntSortedSets.EmptySet, IntSortedSets.Singleton, IntSortedSets.SynchronizedSortedSet, IntSortedSets.UnmodifiableSortedSet

public interface IntIterable
extends java.lang.Iterable<java.lang.Integer>
A type-specific Iterable that strengthens that specification of iterator() and forEach(Consumer).

Note that whenever there exist a primitive consumer in java.util.function (e.g., IntConsumer), trying to access any version of forEach(Consumer) using a lambda expression with untyped arguments will generate an ambiguous method error. This can be easily solved by specifying the type of the argument, as in

    intIterable.forEach((int x) -> { // Do something with x });
 

The same problem plagues, for example, PrimitiveIterator.OfInt.forEachRemaining(java.util.function.IntConsumer).

Warning: Java will let you write “colon” for statements with primitive-type loop variables; however, what is (unfortunately) really happening is that at each iteration an unboxing (and, in the case of fastutil type-specific data structures, a boxing) will be performed. Watch out.

See Also:
Iterable
  • Method Summary

    Modifier and Type Method Description
    default void forEach​(IntConsumer action)
    Performs the given action for each element of this type-specific Iterable until all elements have been processed or the action throws an exception.
    default void forEach​(java.util.function.Consumer<? super java.lang.Integer> action)
    Deprecated.
    Please use the corresponding type-specific method instead.
    default void forEach​(java.util.function.IntConsumer action)
    Performs the given action for each element of this type-specific Iterable until all elements have been processed or the action throws an exception.
    default IntIterator intIterator()
    Returns a primitive iterator on the elements of this iterable.
    default IntSpliterator intSpliterator()
    Returns a primitive spliterator on the elements of this iterable.
    IntIterator iterator()
    Returns a type-specific iterator.
    default IntSpliterator spliterator()
    Returns a type-specific spliterator on the elements of this iterable.
  • Method Details

    • iterator

      IntIterator iterator()
      Returns a type-specific iterator.
      Specified by:
      iterator in interface java.lang.Iterable<java.lang.Integer>
      Returns:
      a type-specific iterator.
      See Also:
      Iterable.iterator()
      API Notes:
      Note that this specification strengthens the one given in Iterable.iterator().
    • intIterator

      default IntIterator intIterator()
      Returns a primitive iterator on the elements of this iterable.

      This method is identical to iterator(), as the type-specific iterator is already compatible with the JDK's primitive iterators. It only exists for compatibility with the other primitive types' Iterables that have use for widened iterators.

      Returns:
      a primitive iterator on the elements of this iterable.
      Since:
      8.5.0
    • spliterator

      default IntSpliterator spliterator()
      Returns a type-specific spliterator on the elements of this iterable.
      Specified by:
      spliterator in interface java.lang.Iterable<java.lang.Integer>
      Returns:
      a type-specific spliterator on the elements of this iterable.
      Since:
      8.5.0
      API Notes:
      Note that this specification strengthens the one given in Iterable.spliterator().
    • intSpliterator

      default IntSpliterator intSpliterator()
      Returns a primitive spliterator on the elements of this iterable.

      This method is identical to spliterator(), as the type-specific spliterator is already compatible with the JDK's primitive spliterators. It only exists for compatibility with the other primitive types' Iterables that have use for widened spliterators.

      Returns:
      a primitive spliterator on the elements of this collection.
      Since:
      8.5.0
    • forEach

      default void forEach​(java.util.function.IntConsumer action)
      Performs the given action for each element of this type-specific Iterable until all elements have been processed or the action throws an exception.
      Parameters:
      action - the action to be performed for each element.
      Since:
      8.0.0
      See Also:
      Iterable.forEach(java.util.function.Consumer)
      API Notes:
      Implementing classes should generally override this method, and take the default implementation of the other overloads which will delegate to this method (after proper conversions).
    • forEach

      default void forEach​(IntConsumer action)
      Performs the given action for each element of this type-specific Iterable until all elements have been processed or the action throws an exception.

      WARNING: Overriding this method is almost always a mistake, as this overload only exists to disambiguate. Instead, override the forEach() overload that uses the JDK's primitive consumer type (e.g. IntConsumer).

      If Java supported final default methods, this would be one, but sadly it does not.

      If you checked and are overriding the version with java.util.function.XConsumer, and still see this warning, then your IDE is incorrectly conflating this method with the proper method to override, and you can safely ignore this message.

      Parameters:
      action - the action to be performed for each element.
      Since:
      8.5.0
      See Also:
      Iterable.forEach(java.util.function.Consumer)
    • forEach

      @Deprecated default void forEach​(java.util.function.Consumer<? super java.lang.Integer> action)
      Deprecated.
      Please use the corresponding type-specific method instead.
      Specified by:
      forEach in interface java.lang.Iterable<java.lang.Integer>