public class Iterables extends Object
Iterable
s to List
s and Set
s.
This class is mostly provided for backwards compatibility in applications which were programmed against
concurrent-trees 1.0.0, in which the tree APIs returned lists and sets instead of lazily-evaluated iterables.
Note that in applications which would have simply iterated through the lists and sets returned by the old APIs,
the new approach of returning lazy iterables is more efficient. Applications can iterate the iterables returned
in exactly the same manner, and results will be the same.
These methods are provided for convenience in applications which actually relied on List and Set-specific
features in the objects which were returned.
Most methods in this class are somewhat similar to utilities in Google Guava; but are provided here to avoid a
dependency on Guava. Applications could use either these methods or Guava.Modifier and Type | Method and Description |
---|---|
static int |
count(Iterable<?> iterable)
Counts the number of elements returned by the given
Iterable . |
static <T> List<T> |
toList(Iterable<T> iterable)
|
static <T> Set<T> |
toSet(Iterable<T> iterable)
|
static String |
toString(Iterable<?> iterable)
Returns a string representation of elements returned by the given
Iterable . |
public static <T> List<T> toList(Iterable<T> iterable)
Iterable
into a new List
.
The iteration order of the list returned, will be the same as that of the iterable.
Be aware of the memory implications of copying objects from a lazy iterable into a collection;
usually it's better to just work with the iterable directly (i.e. by iterating it).T
- The type of elements returned by the iterableiterable
- Provides elements to be copied into a new listList
which contains the elements which were returned by the iterablepublic static <T> Set<T> toSet(Iterable<T> iterable)
Iterable
into a new Set
.
The iteration order of the set returned, will be the same as that of the iterable.
Be aware of the memory implications of copying objects from a lazy iterable into a collection;
usually it's better to just work with the iterable directly (i.e. by iterating it).T
- The type of elements returned by the iterableiterable
- Provides elements to be copied into a new setSet
which contains the elements which were returned by the iterablepublic static String toString(Iterable<?> iterable)
Iterable
.iterable
- Provides elements whose toString
representations should be included in the stringIterable
Copyright © 2018. All rights reserved.