Class ListIterate
java.lang.Object
org.eclipse.collections.impl.utility.ListIterate
The ListIterate utility class can be useful for iterating over lists, especially if there
is a desire to return a MutableList from any of the iteration methods.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
allSatisfy
(List<T> list, Predicate<? super T> predicate) static <T,
IV> boolean allSatisfyWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T> boolean
anySatisfy
(List<T> list, Predicate<? super T> predicate) static <T,
IV> boolean anySatisfyWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T> void
appendString
(List<T> list, Appendable appendable, String start, String separator, String end) static <T> RichIterable<RichIterable<T>>
static <T,
A> MutableList<A> static <T,
A, R extends Collection<A>>
Rstatic <T> MutableBooleanList
collectBoolean
(List<T> list, BooleanFunction<? super T> booleanFunction) static <T,
R extends MutableBooleanCollection>
RcollectBoolean
(List<T> list, BooleanFunction<? super T> booleanFunction, R target) static <T> MutableByteList
collectByte
(List<T> list, ByteFunction<? super T> byteFunction) static <T,
R extends MutableByteCollection>
RcollectByte
(List<T> list, ByteFunction<? super T> byteFunction, R target) static <T> MutableCharList
collectChar
(List<T> list, CharFunction<? super T> charFunction) static <T,
R extends MutableCharCollection>
RcollectChar
(List<T> list, CharFunction<? super T> charFunction, R target) static <T> MutableDoubleList
collectDouble
(List<T> list, DoubleFunction<? super T> doubleFunction) static <T,
R extends MutableDoubleCollection>
RcollectDouble
(List<T> list, DoubleFunction<? super T> doubleFunction, R target) static <T> MutableFloatList
collectFloat
(List<T> list, FloatFunction<? super T> floatFunction) static <T,
R extends MutableFloatCollection>
RcollectFloat
(List<T> list, FloatFunction<? super T> floatFunction, R target) static <T,
A> MutableList<A> static <T,
A, R extends Collection<A>>
RcollectIf
(List<T> list, Predicate<? super T> predicate, Function<? super T, ? extends A> function, R targetCollection) static <T> MutableIntList
collectInt
(List<T> list, IntFunction<? super T> intFunction) static <T,
R extends MutableIntCollection>
RcollectInt
(List<T> list, IntFunction<? super T> intFunction, R target) static <T> MutableLongList
collectLong
(List<T> list, LongFunction<? super T> longFunction) static <T,
R extends MutableLongCollection>
RcollectLong
(List<T> list, LongFunction<? super T> longFunction, R target) static <T> MutableShortList
collectShort
(List<T> list, ShortFunction<? super T> shortFunction) static <T,
R extends MutableShortCollection>
RcollectShort
(List<T> list, ShortFunction<? super T> shortFunction, R target) static <T,
P, A> MutableList<A> collectWith
(List<T> list, Function2<? super T, ? super P, ? extends A> function, P parameter) static <T,
P, A, R extends Collection<A>>
RcollectWith
(List<T> list, Function2<? super T, ? super P, ? extends A> function, P parameter, R targetCollection) static <T,
A> MutableList<A> collectWithIndex
(List<T> list, ObjectIntToObjectFunction<? super T, ? extends A> function) static <T,
A, R extends Collection<A>>
RcollectWithIndex
(List<T> list, ObjectIntToObjectFunction<? super T, ? extends A> function, R targetCollection) static <T> int
static <T,
IV> int countWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T> T
static <T> T
detectIfNone
(List<T> list, Predicate<? super T> predicate, T ifNone) static <T> int
detectIndex
(List<T> list, Predicate<? super T> predicate) Searches for the first index where the predicate evaluates to true.static <T,
P> int detectIndexWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) Searches for the first index where the predicate2 and parameter evaluates to true.static <T> int
detectLastIndex
(List<T> list, Predicate<? super T> predicate) Returns the last index where the predicate evaluates to true.static <T> Optional<T>
detectOptional
(List<T> list, Predicate<? super T> predicate) static <T,
IV> T detectWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T,
IV> T detectWithIfNone
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue, T ifNone) static <T,
IV> Optional<T> detectWithOptional
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T> MutableList<T>
static <T> MutableList<T>
distinct
(List<T> list, HashingStrategy<? super T> hashingStrategy) static <T,
R extends List<T>>
RDeprecated.in 7.0.static <T,
V> MutableList<T> distinctBy
(List<T> list, Function<? super T, ? extends V> function) static <T> MutableList<T>
static <T,
R extends Collection<T>>
Rstatic <T> MutableList<T>
static boolean
static <T,
A> MutableList<A> flatCollect
(List<T> list, Function<? super T, ? extends Iterable<A>> function) static <T,
A, R extends Collection<A>>
RflatCollect
(List<T> list, Function<? super T, ? extends Iterable<A>> function, R targetCollection) static <T> void
Iterates over the section of the list covered by the specified indexes.static <T> void
static <T1,
T2> void forEachInBoth
(List<T1> list1, List<T2> list2, Procedure2<? super T1, ? super T2> procedure) Iterates over both lists together, evaluating Procedure2 with the current element from each list.static <T,
P> void forEachWith
(List<T> list, Procedure2<? super T, ? super P> procedure, P parameter) static <T> void
forEachWithIndex
(List<T> list, int from, int to, ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the section of the list covered by the specified indexes.static <T> void
forEachWithIndex
(List<T> list, ObjectIntProcedure<? super T> objectIntProcedure) static <T> T
Returns the first element of a list.static <T> T
Returns the last element of a list.static <T,
V> FastListMultimap<V, T> static <T,
V, R extends MutableMultimap<V, T>>
Rstatic <T,
V> FastListMultimap<V, T> groupByEach
(List<T> list, Function<? super T, ? extends Iterable<V>> function) static <T,
V, R extends MutableMultimap<V, T>>
RgroupByEach
(List<T> list, Function<? super T, ? extends Iterable<V>> function, R target) static <K,
T> MutableMap<K, T> groupByUniqueKey
(List<T> list, Function<? super T, ? extends K> function) static <K,
T, R extends MutableMapIterable<K, T>>
RgroupByUniqueKey
(List<T> list, Function<? super T, ? extends K> function, R target) static <T> double
injectInto
(double injectValue, List<T> list, DoubleObjectToDoubleFunction<? super T> function) static <T> float
injectInto
(float injectValue, List<T> list, FloatObjectToFloatFunction<? super T> function) static <T> int
injectInto
(int injectValue, List<T> list, IntObjectToIntFunction<? super T> function) static <T> long
injectInto
(long injectValue, List<T> list, LongObjectToLongFunction<? super T> function) static <T,
IV> IV injectInto
(IV injectValue, List<T> list, Function2<? super IV, ? super T, ? extends IV> function) static <T,
IV, P> IV injectIntoWith
(IV injectedValue, List<T> list, Function3<? super IV, ? super T, ? super P, ? extends IV> function, P parameter) static <T> T
static <T> T
max
(List<T> list, Comparator<? super T> comparator) static <T,
V extends Comparable<? super V>>
Tstatic <T> T
static <T> T
min
(List<T> list, Comparator<? super T> comparator) static <T,
V extends Comparable<? super V>>
Tstatic <T> boolean
noneSatisfy
(List<T> list, Predicate<? super T> predicate) static <T,
P> boolean noneSatisfyWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P injectedValue) static <T> PartitionMutableList<T>
static <T> PartitionMutableList<T>
partitionWhile
(List<T> list, Predicate<? super T> predicate) static <T,
P> PartitionMutableList<T> partitionWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) static void
rangeCheck
(int from, int to, int size) static <T> MutableList<T>
static <T,
R extends Collection<T>>
Rstatic <T,
IV> MutableList<T> rejectWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T,
P, R extends Collection<T>>
RrejectWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, R targetCollection) static <T> boolean
static <T> boolean
static <T,
P> boolean removeIfWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) static <T,
P> boolean removeIfWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, Procedure<? super T> procedure) static <T> void
reverseForEach
(List<T> list, Procedure<? super T> procedure) Iterates over the List in reverse order executing the Procedure for each elementstatic <T> void
reverseForEachWithIndex
(List<T> list, ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the List in reverse order executing the Procedure for each element.static <T> List<T>
reverseThis
(List<T> list) Reverses the order of the items in the list.static <T> MutableList<T>
static <T,
R extends Collection<T>>
Rstatic <T,
IV> Twin<MutableList<T>> selectAndRejectWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T,
S> MutableList<S> selectInstancesOf
(List<T> list, Class<S> clazz) static <T,
IV> MutableList<T> selectWith
(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) static <T,
P, R extends Collection<T>>
RselectWith
(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, R targetCollection) static <V,
T> MutableMap<V, BigDecimal> sumByBigDecimal
(List<T> list, Function<T, V> groupBy, Function<? super T, BigDecimal> function) static <V,
T> MutableMap<V, BigInteger> sumByBigInteger
(List<T> list, Function<T, V> groupBy, Function<? super T, BigInteger> function) static <V,
T> ObjectDoubleMap<V> sumByDouble
(List<T> list, Function<T, V> groupBy, DoubleFunction<? super T> function) static <V,
T> ObjectDoubleMap<V> sumByFloat
(List<T> list, Function<T, V> groupBy, FloatFunction<? super T> function) static <V,
T> ObjectLongMap<V> sumByInt
(List<T> list, Function<T, V> groupBy, IntFunction<? super T> function) static <V,
T> ObjectLongMap<V> sumByLong
(List<T> list, Function<T, V> groupBy, LongFunction<? super T> function) static <T> BigDecimal
sumOfBigDecimal
(List<T> list, Function<? super T, BigDecimal> function) static <T> BigInteger
sumOfBigInteger
(List<T> list, Function<? super T, BigInteger> function) static <T> double
sumOfDouble
(List<T> list, DoubleFunction<? super T> function) static <T> double
sumOfFloat
(List<T> list, FloatFunction<? super T> function) static <T> long
sumOfInt
(List<T> list, IntFunction<? super T> function) static <T> long
sumOfLong
(List<T> list, LongFunction<? super T> function) static <T> MutableList<T>
static <T,
R extends Collection<T>>
Rstatic <T> MutableList<T>
static <T> void
static <X,
Y> MutableList<Pair<X, Y>> static <X,
Y, R extends Collection<Pair<X, Y>>>
Rstatic <T> MutableList<Pair<T,
Integer>> zipWithIndex
(List<T> list) static <T,
R extends Collection<Pair<T, Integer>>>
RzipWithIndex
(List<T> list, R target)
-
Method Details
-
equals
-
toArray
-
select
- See Also:
-
selectWith
public static <T,IV> MutableList<T> selectWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
select
public static <T,R extends Collection<T>> R select(List<T> list, Predicate<? super T> predicate, R targetCollection) -
selectWith
public static <T,P, R selectWithR extends Collection<T>> (List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, R targetCollection) -
selectInstancesOf
-
count
- See Also:
-
countWith
public static <T,IV> int countWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
collectIf
public static <T,A> MutableList<A> collectIf(List<T> list, Predicate<? super T> predicate, Function<? super T, ? extends A> function) -
collectIf
public static <T,A, R collectIfR extends Collection<A>> (List<T> list, Predicate<? super T> predicate, Function<? super T, ? extends A> function, R targetCollection) -
reject
- See Also:
-
rejectWith
public static <T,IV> MutableList<T> rejectWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
reject
public static <T,R extends Collection<T>> R reject(List<T> list, Predicate<? super T> predicate, R targetCollection) -
rejectWith
public static <T,P, R rejectWithR extends Collection<T>> (List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, R targetCollection) -
collect
- See Also:
-
collect
public static <T,A, R collectR extends Collection<A>> (List<T> list, Function<? super T, ? extends A> function, R targetCollection) -
collectWithIndex
public static <T,A> MutableList<A> collectWithIndex(List<T> list, ObjectIntToObjectFunction<? super T, ? extends A> function) - Since:
- 9.1
-
collectWithIndex
public static <T,A, R collectWithIndexR extends Collection<A>> (List<T> list, ObjectIntToObjectFunction<? super T, ? extends A> function, R targetCollection) - Since:
- 9.1
-
collectBoolean
public static <T> MutableBooleanList collectBoolean(List<T> list, BooleanFunction<? super T> booleanFunction) -
collectBoolean
public static <T,R extends MutableBooleanCollection> R collectBoolean(List<T> list, BooleanFunction<? super T> booleanFunction, R target) -
collectByte
-
collectByte
public static <T,R extends MutableByteCollection> R collectByte(List<T> list, ByteFunction<? super T> byteFunction, R target) -
collectChar
-
collectChar
public static <T,R extends MutableCharCollection> R collectChar(List<T> list, CharFunction<? super T> charFunction, R target) -
collectDouble
public static <T> MutableDoubleList collectDouble(List<T> list, DoubleFunction<? super T> doubleFunction) -
collectDouble
public static <T,R extends MutableDoubleCollection> R collectDouble(List<T> list, DoubleFunction<? super T> doubleFunction, R target) -
collectFloat
public static <T> MutableFloatList collectFloat(List<T> list, FloatFunction<? super T> floatFunction) -
collectFloat
public static <T,R extends MutableFloatCollection> R collectFloat(List<T> list, FloatFunction<? super T> floatFunction, R target) -
collectInt
-
collectInt
public static <T,R extends MutableIntCollection> R collectInt(List<T> list, IntFunction<? super T> intFunction, R target) -
collectLong
-
collectLong
public static <T,R extends MutableLongCollection> R collectLong(List<T> list, LongFunction<? super T> longFunction, R target) -
collectShort
public static <T> MutableShortList collectShort(List<T> list, ShortFunction<? super T> shortFunction) -
collectShort
public static <T,R extends MutableShortCollection> R collectShort(List<T> list, ShortFunction<? super T> shortFunction, R target) -
flatCollect
public static <T,A> MutableList<A> flatCollect(List<T> list, Function<? super T, ? extends Iterable<A>> function) - See Also:
-
flatCollect
public static <T,A, R flatCollectR extends Collection<A>> (List<T> list, Function<? super T, ? extends Iterable<A>> function, R targetCollection) -
getFirst
Returns the first element of a list. -
getLast
Returns the last element of a list. -
forEach
- See Also:
-
reverseForEach
Iterates over the List in reverse order executing the Procedure for each element -
reverseForEachWithIndex
public static <T> void reverseForEachWithIndex(List<T> list, ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the List in reverse order executing the Procedure for each element. The index passed into the ObjectIntProcedure is the actual index of the range. -
forEach
Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the list is iterated in the reverse order.e.g. MutableList<People> people = FastList.newListWith(ted, mary, bob, sally); ListIterate.forEach(people, 0, 1, new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
-
forEachWithIndex
public static <T> void forEachWithIndex(List<T> list, int from, int to, ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the list is iterated in the reverse order. The index passed into the ObjectIntProcedure is the actual index of the range.e.g. MutableList<People> people = FastList.newListWith(ted, mary, bob, sally); ListIterate.forEachWithIndex(people, 0, 1, new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info(person.getName() + " at index: " + index); } });
This code would output ted and mary's names.
-
rangeCheck
public static void rangeCheck(int from, int to, int size) -
forEachInBoth
public static <T1,T2> void forEachInBoth(List<T1> list1, List<T2> list2, Procedure2<? super T1, ? super T2> procedure) Iterates over both lists together, evaluating Procedure2 with the current element from each list. -
forEachWithIndex
public static <T> void forEachWithIndex(List<T> list, ObjectIntProcedure<? super T> objectIntProcedure) -
detect
- See Also:
-
detectWith
public static <T,IV> T detectWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
detectOptional
-
detectWithOptional
public static <T,IV> Optional<T> detectWithOptional(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
detectIfNone
-
detectWithIfNone
public static <T,IV> T detectWithIfNone(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue, T ifNone) -
injectInto
-
injectInto
public static <T> int injectInto(int injectValue, List<T> list, IntObjectToIntFunction<? super T> function) -
injectInto
public static <T> long injectInto(long injectValue, List<T> list, LongObjectToLongFunction<? super T> function) -
injectInto
public static <T> double injectInto(double injectValue, List<T> list, DoubleObjectToDoubleFunction<? super T> function) -
injectInto
public static <T> float injectInto(float injectValue, List<T> list, FloatObjectToFloatFunction<? super T> function) -
sumOfInt
-
sumOfLong
-
sumOfFloat
-
sumOfDouble
-
sumOfBigDecimal
-
sumOfBigInteger
-
sumByBigDecimal
public static <V,T> MutableMap<V,BigDecimal> sumByBigDecimal(List<T> list, Function<T, V> groupBy, Function<? super T, BigDecimal> function) -
sumByBigInteger
public static <V,T> MutableMap<V,BigInteger> sumByBigInteger(List<T> list, Function<T, V> groupBy, Function<? super T, BigInteger> function) -
sumByInt
public static <V,T> ObjectLongMap<V> sumByInt(List<T> list, Function<T, V> groupBy, IntFunction<? super T> function) -
sumByLong
public static <V,T> ObjectLongMap<V> sumByLong(List<T> list, Function<T, V> groupBy, LongFunction<? super T> function) -
sumByFloat
public static <V,T> ObjectDoubleMap<V> sumByFloat(List<T> list, Function<T, V> groupBy, FloatFunction<? super T> function) -
sumByDouble
public static <V,T> ObjectDoubleMap<V> sumByDouble(List<T> list, Function<T, V> groupBy, DoubleFunction<? super T> function) -
anySatisfy
- See Also:
-
anySatisfyWith
public static <T,IV> boolean anySatisfyWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
allSatisfy
- See Also:
-
allSatisfyWith
public static <T,IV> boolean allSatisfyWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
noneSatisfy
- See Also:
-
noneSatisfyWith
public static <T,P> boolean noneSatisfyWith(List<T> list, Predicate2<? super T, ? super P> predicate, P injectedValue) -
selectAndRejectWith
public static <T,IV> Twin<MutableList<T>> selectAndRejectWith(List<T> list, Predicate2<? super T, ? super IV> predicate, IV injectedValue) -
partition
- See Also:
-
partitionWith
public static <T,P> PartitionMutableList<T> partitionWith(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) -
removeIf
- See Also:
-
removeIfWith
public static <T,P> boolean removeIfWith(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) -
removeIf
-
removeIfWith
public static <T,P> boolean removeIfWith(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter, Procedure<? super T> procedure) -
detectIndex
Searches for the first index where the predicate evaluates to true. -
detectIndexWith
public static <T,P> int detectIndexWith(List<T> list, Predicate2<? super T, ? super P> predicate, P parameter) Searches for the first index where the predicate2 and parameter evaluates to true. -
detectLastIndex
Returns the last index where the predicate evaluates to true. Returns -1 for no matches. -
injectIntoWith
-
forEachWith
public static <T,P> void forEachWith(List<T> list, Procedure2<? super T, ? super P> procedure, P parameter) -
collectWith
public static <T,P, MutableList<A> collectWithA> (List<T> list, Function2<? super T, ? super P, ? extends A> function, P parameter) -
collectWith
public static <T,P, R collectWithA, R extends Collection<A>> (List<T> list, Function2<? super T, ? super P, ? extends A> function, P parameter, R targetCollection) -
distinct
Deprecated.in 7.0. -
distinct
- Since:
- 7.0.
-
distinct
- Since:
- 7.0.
-
distinctBy
public static <T,V> MutableList<T> distinctBy(List<T> list, Function<? super T, ? extends V> function) - Since:
- 9.0
-
reverseThis
Reverses the order of the items in the list.List<Integer> integers = Lists.fixedSize.of(1, 3, 2); Verify.assertListsEqual(FastList.newListWith(2, 3, 1), ListIterate.reverse(integers));
- Returns:
- the reversed list
-
take
- See Also:
-
take
- See Also:
-
drop
- See Also:
-
drop
- See Also:
-
appendString
public static <T> void appendString(List<T> list, Appendable appendable, String start, String separator, String end) -
groupBy
public static <T,V> FastListMultimap<V,T> groupBy(List<T> list, Function<? super T, ? extends V> function) - See Also:
-
groupBy
public static <T,V, R groupByR extends MutableMultimap<V, T>> (List<T> list, Function<? super T, ? extends V> function, R target) -
groupByEach
public static <T,V> FastListMultimap<V,T> groupByEach(List<T> list, Function<? super T, ? extends Iterable<V>> function) - See Also:
-
groupByEach
public static <T,V, R groupByEachR extends MutableMultimap<V, T>> (List<T> list, Function<? super T, ? extends Iterable<V>> function, R target) -
groupByUniqueKey
public static <K,T> MutableMap<K,T> groupByUniqueKey(List<T> list, Function<? super T, ? extends K> function) -
groupByUniqueKey
public static <K,T, R groupByUniqueKeyR extends MutableMapIterable<K, T>> (List<T> list, Function<? super T, ? extends K> function, R target) -
min
- See Also:
-
minBy
public static <T,V extends Comparable<? super V>> T minBy(List<T> list, Function<? super T, ? extends V> function) -
maxBy
public static <T,V extends Comparable<? super V>> T maxBy(List<T> list, Function<? super T, ? extends V> function) -
max
- See Also:
-
min
- See Also:
-
max
- See Also:
-
chunk
- See Also:
-
zip
- See Also:
-
zip
public static <X,Y, R zipR extends Collection<Pair<X, Y>>> (List<X> list, Iterable<Y> iterable, R target) -
zipWithIndex
- See Also:
-
zipWithIndex
-
takeWhile
- See Also:
-
dropWhile
- See Also:
-
partitionWhile
public static <T> PartitionMutableList<T> partitionWhile(List<T> list, Predicate<? super T> predicate) - See Also:
-