A comprehensive collections framework API for Java providing interfaces for object collections, primitive collections and lazy iterables
—
Eclipse Collections provides memory-efficient primitive collections for all 8 Java primitive types (boolean, byte, char, double, float, int, long, short), avoiding the performance overhead of autoboxing. Each primitive type has corresponding List, Set, Bag, Stack, and Map collections with both mutable and immutable variants.
Base interface for all primitive collection types.
package org.eclipse.collections.api;
public interface PrimitiveIterable {
int size();
boolean isEmpty();
boolean notEmpty();
// String representation
String makeString();
String makeString(String separator);
String makeString(String start, String separator, String end);
void appendString(Appendable appendable);
void appendString(Appendable appendable, String separator);
void appendString(Appendable appendable, String start, String separator, String end);
}Each primitive type has its own base iterable interface:
// Boolean collections
package org.eclipse.collections.api;
public interface BooleanIterable extends PrimitiveIterable {
BooleanIterator booleanIterator();
// Primitive operations
boolean[] toArray();
boolean contains(boolean value);
boolean containsAll(boolean... source);
boolean containsAll(BooleanIterable source);
// Functional operations
void forEach(BooleanProcedure procedure);
BooleanIterable select(BooleanPredicate predicate);
BooleanIterable reject(BooleanPredicate predicate);
<V> RichIterable<V> collect(BooleanToObjectFunction<? extends V> function);
// Aggregation
int count(BooleanPredicate predicate);
boolean anySatisfy(BooleanPredicate predicate);
boolean allSatisfy(BooleanPredicate predicate);
boolean noneSatisfy(BooleanPredicate predicate);
// Conversion
MutableBooleanList toList();
MutableBooleanSet toSet();
MutableBooleanBag toBag();
}
// Integer collections (representative of all numeric primitive types)
package org.eclipse.collections.api.iterator;
public interface IntIterable extends PrimitiveIterable {
IntIterator intIterator();
// Primitive operations
int[] toArray();
boolean contains(int value);
boolean containsAll(int... source);
boolean containsAll(IntIterable source);
// Functional operations
void forEach(IntProcedure procedure);
IntIterable select(IntPredicate predicate);
IntIterable reject(IntPredicate predicate);
<V> RichIterable<V> collect(IntToObjectFunction<? extends V> function);
// Mathematical operations
long sum();
int max();
int min();
double average();
double median();
int[] toSortedArray();
// Aggregation
int count(IntPredicate predicate);
boolean anySatisfy(IntPredicate predicate);
boolean allSatisfy(IntPredicate predicate);
boolean noneSatisfy(IntPredicate predicate);
int detectIfNone(IntPredicate predicate, int ifNone);
// Conversion
MutableIntList toList();
MutableIntSet toSet();
MutableIntBag toBag();
LazyIntIterable asLazy();
}Mutable primitive list avoiding boxing overhead for integers.
package org.eclipse.collections.api.list.primitive;
public interface MutableIntList extends IntIterable {
// List access operations
int get(int index);
int getFirst();
int getLast();
int indexOf(int value);
int lastIndexOf(int value);
// Modification operations
void add(int element);
boolean addAll(int... source);
boolean addAll(IntIterable source);
void addAtIndex(int index, int element);
boolean addAllAtIndex(int index, int... source);
boolean addAllAtIndex(int index, IntIterable source);
boolean remove(int value);
int removeAtIndex(int index);
void clear();
// List-specific operations
int set(int index, int element);
MutableIntList subList(int fromIndex, int toIndex);
void sortThis();
MutableIntList reverseThis();
void shuffleThis();
void shuffleThis(Random rnd);
// Functional operations
MutableIntList select(IntPredicate predicate);
MutableIntList reject(IntPredicate predicate);
<V> MutableList<V> collect(IntToObjectFunction<? extends V> function);
// Primitive transformations
MutableLongList collectLong(IntToLongFunction function);
MutableDoubleList collectDouble(IntToDoubleFunction function);
// With operations
MutableIntList with(int element);
MutableIntList without(int element);
MutableIntList withAll(IntIterable elements);
MutableIntList withoutAll(IntIterable elements);
// Immutable copy
ImmutableIntList toImmutable();
}Thread-safe immutable primitive list where all operations return new instances.
package org.eclipse.collections.api.list.primitive;
public interface ImmutableIntList extends IntIterable {
// List access operations
int get(int index);
int getFirst();
int getLast();
int indexOf(int value);
int lastIndexOf(int value);
// Sublist operations return new instances
ImmutableIntList subList(int fromIndex, int toIndex);
ImmutableIntList toReversed();
// Modification operations return new instances
ImmutableIntList newWith(int element);
ImmutableIntList newWithout(int element);
ImmutableIntList newWithAll(IntIterable elements);
ImmutableIntList newWithoutAll(IntIterable elements);
// Functional operations return new instances
ImmutableIntList select(IntPredicate predicate);
ImmutableIntList reject(IntPredicate predicate);
<V> ImmutableList<V> collect(IntToObjectFunction<? extends V> function);
// Primitive transformations return new instances
ImmutableLongList collectLong(IntToLongFunction function);
ImmutableDoubleList collectDouble(IntToDoubleFunction function);
}Mutable primitive set with unique elements and set operations.
package org.eclipse.collections.api.set.primitive;
public interface MutableIntSet extends IntIterable {
// Set modification operations
boolean add(int element);
boolean addAll(int... source);
boolean addAll(IntIterable source);
boolean remove(int value);
boolean removeAll(IntIterable source);
boolean removeAll(int... source);
boolean retainAll(IntIterable source);
boolean retainAll(int... source);
void clear();
// Set operations
MutableIntSet union(IntIterable set);
MutableIntSet intersect(IntIterable set);
MutableIntSet difference(IntIterable subtrahendSet);
MutableIntSet symmetricDifference(IntIterable setB);
// Functional operations
MutableIntSet select(IntPredicate predicate);
MutableIntSet reject(IntPredicate predicate);
<V> MutableSet<V> collect(IntToObjectFunction<? extends V> function);
// With operations
MutableIntSet with(int element);
MutableIntSet without(int element);
MutableIntSet withAll(IntIterable elements);
MutableIntSet withoutAll(IntIterable elements);
// Immutable copy
ImmutableIntSet toImmutable();
}Thread-safe immutable primitive set where all operations return new instances.
package org.eclipse.collections.api.set.primitive;
public interface ImmutableIntSet extends IntIterable {
// Set operations return new instances
ImmutableIntSet union(IntIterable set);
ImmutableIntSet intersect(IntIterable set);
ImmutableIntSet difference(IntIterable subtrahendSet);
ImmutableIntSet symmetricDifference(IntIterable setB);
// Modification operations return new instances
ImmutableIntSet newWith(int element);
ImmutableIntSet newWithout(int element);
ImmutableIntSet newWithAll(IntIterable elements);
ImmutableIntSet newWithoutAll(IntIterable elements);
// Functional operations return new instances
ImmutableIntSet select(IntPredicate predicate);
ImmutableIntSet reject(IntPredicate predicate);
<V> ImmutableSet<V> collect(IntToObjectFunction<? extends V> function);
}Mutable primitive bag with occurrence counting for duplicates.
package org.eclipse.collections.api.bag.primitive;
public interface MutableIntBag extends IntIterable {
// Occurrence operations
int occurrencesOf(int item);
void forEachWithOccurrences(IntIntProcedure procedure);
// Bag modification operations
boolean add(int item);
boolean remove(int item);
boolean addOccurrences(int item, int occurrences);
boolean removeOccurrences(int item, int occurrences);
boolean setOccurrences(int item, int occurrences);
// Bag operations
int sizeDistinct();
MutableIntBag selectByOccurrences(IntPredicate predicate);
// Functional operations
MutableIntBag select(IntPredicate predicate);
MutableIntBag reject(IntPredicate predicate);
<V> MutableBag<V> collect(IntToObjectFunction<? extends V> function);
// With operations
MutableIntBag with(int element);
MutableIntBag without(int element);
MutableIntBag withAll(IntIterable elements);
MutableIntBag withoutAll(IntIterable elements);
// Immutable copy
ImmutableIntBag toImmutable();
}Thread-safe immutable primitive bag where all operations return new instances.
package org.eclipse.collections.api.bag.primitive;
public interface ImmutableIntBag extends IntIterable {
// Occurrence operations
int occurrencesOf(int item);
void forEachWithOccurrences(IntIntProcedure procedure);
// Bag operations
int sizeDistinct();
ImmutableIntBag selectByOccurrences(IntPredicate predicate);
// Modification operations return new instances
ImmutableIntBag newWith(int element);
ImmutableIntBag newWithout(int element);
ImmutableIntBag newWithAll(IntIterable elements);
ImmutableIntBag newWithoutAll(IntIterable elements);
ImmutableIntBag newWithOccurrences(int item, int occurrences);
// Functional operations return new instances
ImmutableIntBag select(IntPredicate predicate);
ImmutableIntBag reject(IntPredicate predicate);
<V> ImmutableBag<V> collect(IntToObjectFunction<? extends V> function);
}Mutable primitive stack with LIFO operations.
package org.eclipse.collections.api.stack.primitive;
public interface MutableIntStack extends IntIterable {
// Stack operations
void push(int item);
int pop();
int peek();
int peekAt(int index);
IntList peek(int count);
IntList pop(int count);
void clear();
// Functional operations
MutableIntStack select(IntPredicate predicate);
MutableIntStack reject(IntPredicate predicate);
<V> MutableStack<V> collect(IntToObjectFunction<? extends V> function);
// With operations
MutableIntStack with(int element);
MutableIntStack without(int element);
// Immutable copy
ImmutableIntStack toImmutable();
}Thread-safe immutable primitive stack where all operations return new instances.
package org.eclipse.collections.api.stack.primitive;
public interface ImmutableIntStack extends IntIterable {
// Stack operations return new instances
ImmutableIntStack push(int item);
ImmutableIntStack pop();
ImmutableIntStack pop(int count);
// Stack access operations
int peek();
int peekAt(int index);
IntList peek(int count);
// Modification operations return new instances
ImmutableIntStack newWith(int element);
ImmutableIntStack newWithout(int element);
// Functional operations return new instances
ImmutableIntStack select(IntPredicate predicate);
ImmutableIntStack reject(IntPredicate predicate);
<V> ImmutableStack<V> collect(IntToObjectFunction<? extends V> function);
}Primitive maps provide efficient key-value storage avoiding boxing overhead. There are three variants for each primitive type combination:
// ObjectIntMap - Object keys to int values
package org.eclipse.collections.api.map.primitive;
public interface ObjectIntMap<K> extends IntIterable {
// Map operations
int get(Object key);
int getIfAbsent(Object key, int ifAbsent);
int getOrThrow(Object key);
boolean containsKey(Object key);
boolean containsValue(int value);
// Iteration
void forEachKey(Procedure<? super K> procedure);
void forEachValue(IntProcedure procedure);
void forEachKeyValue(ObjectIntProcedure<? super K> procedure);
// Views
RichIterable<K> keysView();
IntIterable values();
// Conversion
MutableObjectIntMap<K> toMap();
ImmutableObjectIntMap<K> toImmutable();
}
public interface MutableObjectIntMap<K> extends ObjectIntMap<K> {
// Modification operations
void put(K key, int value);
void putPair(ObjectIntPair<K> keyValuePair);
void putAll(ObjectIntMap<? extends K> map);
int updateValue(K key, int initialValueIfAbsent, IntToIntFunction function);
// Removal operations
void removeKey(K key);
void remove(Object key);
int removeKeyIfAbsent(K key, int value);
void clear();
// Functional operations
MutableObjectIntMap<K> select(ObjectIntPredicate<? super K> predicate);
MutableObjectIntMap<K> reject(ObjectIntPredicate<? super K> predicate);
// With operations
MutableObjectIntMap<K> withKeyValue(K key, int value);
MutableObjectIntMap<K> withoutKey(K key);
ImmutableObjectIntMap<K> toImmutable();
}
public interface ImmutableObjectIntMap<K> extends ObjectIntMap<K> {
// Modification operations return new instances
ImmutableObjectIntMap<K> newWithKeyValue(K key, int value);
ImmutableObjectIntMap<K> newWithoutKey(K key);
ImmutableObjectIntMap<K> newWithAllKeyValues(Iterable<ObjectIntPair<K>> keyValues);
ImmutableObjectIntMap<K> newWithoutAllKeys(Iterable<? extends K> keys);
// Functional operations return new instances
ImmutableObjectIntMap<K> select(ObjectIntPredicate<? super K> predicate);
ImmutableObjectIntMap<K> reject(ObjectIntPredicate<? super K> predicate);
}// IntObjectMap - int keys to Object values
package org.eclipse.collections.api.map.primitive;
public interface IntObjectMap<V> extends RichIterable<V> {
// Map operations
V get(int key);
V getIfAbsent(int key, Function0<? extends V> ifAbsent);
V getIfAbsentPut(int key, V value);
V getIfAbsentPut(int key, Function0<? extends V> function);
boolean containsKey(int key);
boolean containsValue(Object value);
// Iteration
void forEachKey(IntProcedure procedure);
void forEachValue(Procedure<? super V> procedure);
void forEachKeyValue(IntObjectProcedure<? super V> procedure);
// Views
IntIterable keysView();
RichIterable<V> valuesView();
// Conversion
MutableIntObjectMap<V> toMap();
ImmutableIntObjectMap<V> toImmutable();
}
public interface MutableIntObjectMap<V> extends IntObjectMap<V> {
// Modification operations
V put(int key, V value);
void putPair(IntObjectPair<V> keyValuePair);
void putAll(IntObjectMap<? extends V> map);
V updateValue(int key, Function0<? extends V> factory, Function<? super V, ? extends V> function);
// Removal operations
void removeKey(int key);
void remove(int key);
V removeKeyIfAbsent(int key, V value);
void clear();
// Functional operations
<VV> MutableIntObjectMap<VV> collectValues(Function2<? super Integer, ? super V, ? extends VV> function);
MutableIntObjectMap<V> select(IntObjectPredicate<? super V> predicate);
MutableIntObjectMap<V> reject(IntObjectPredicate<? super V> predicate);
// With operations
MutableIntObjectMap<V> withKeyValue(int key, V value);
MutableIntObjectMap<V> withoutKey(int key);
ImmutableIntObjectMap<V> toImmutable();
}// IntIntMap - int keys to int values
package org.eclipse.collections.api.map.primitive;
public interface IntIntMap extends IntIterable {
// Map operations
int get(int key);
int getIfAbsent(int key, int ifAbsent);
int getOrThrow(int key);
boolean containsKey(int key);
boolean containsValue(int value);
// Iteration
void forEachKey(IntProcedure procedure);
void forEachValue(IntProcedure procedure);
void forEachKeyValue(IntIntProcedure procedure);
// Views
IntIterable keysView();
IntIterable values();
// Conversion
MutableIntIntMap toMap();
ImmutableIntIntMap toImmutable();
}
public interface MutableIntIntMap extends IntIntMap {
// Modification operations
void put(int key, int value);
void putPair(IntIntPair keyValuePair);
void putAll(IntIntMap map);
int addToValue(int key, int toBeAdded);
int updateValue(int key, int initialValueIfAbsent, IntToIntFunction function);
// Removal operations
void removeKey(int key);
void remove(int key);
int removeKeyIfAbsent(int key, int value);
void clear();
// Functional operations
MutableIntIntMap select(IntIntPredicate predicate);
MutableIntIntMap reject(IntIntPredicate predicate);
// With operations
MutableIntIntMap withKeyValue(int key, int value);
MutableIntIntMap withoutKey(int key);
ImmutableIntIntMap toImmutable();
}Eclipse Collections provides the above interfaces for all 8 primitive types:
BooleanIterable, MutableBooleanList, ImmutableBooleanListMutableBooleanSet, ImmutableBooleanSetMutableBooleanBag, ImmutableBooleanBagMutableBooleanStack, ImmutableBooleanStackObjectBooleanMap, BooleanObjectMap, BooleanBooleanMapByteIterable, MutableByteList, ImmutableByteListMutableByteSet, ImmutableByteSetMutableByteBag, ImmutableByteBagMutableByteStack, ImmutableByteStackObjectByteMap, ByteObjectMap, ByteByteMap, plus cross-type maps like ByteIntMapCharIterable, MutableCharList, ImmutableCharListMutableCharSet, ImmutableCharSetMutableCharBag, ImmutableCharBagMutableCharStack, ImmutableCharStackObjectCharMap, CharObjectMap, CharCharMap, plus cross-type mapsEach follows the same pattern as shown above with type-specific mathematical operations:
DoubleIterable, FloatIterable, IntIterable, LongIterable, ShortIterable// Create primitive lists
MutableIntList numbers = IntLists.mutable.with(1, 2, 3, 4, 5);
// Mathematical operations (no boxing)
long sum = numbers.sum(); // 15
int max = numbers.max(); // 5
double average = numbers.average(); // 3.0
// Functional operations
MutableIntList evens = numbers.select(n -> n % 2 == 0); // [2, 4]
MutableLongList squares = numbers.collectLong(n -> n * n); // [1, 4, 9, 16, 25]// Create primitive sets
MutableIntSet set1 = IntSets.mutable.with(1, 2, 3);
MutableIntSet set2 = IntSets.mutable.with(3, 4, 5);
// Set operations (no boxing)
MutableIntSet union = set1.union(set2); // [1, 2, 3, 4, 5]
MutableIntSet intersection = set1.intersect(set2); // [3]// Create primitive maps
MutableObjectIntMap<String> counts = ObjectIntMaps.mutable.empty();
counts.put("apple", 5);
counts.put("banana", 3);
// Efficient operations (no boxing)
int appleCount = counts.get("apple"); // 5
counts.addToValue("apple", 2); // apple now has 7
int total = counts.sum(); // 10
// Primitive-to-primitive maps
MutableIntIntMap squares = IntIntMaps.mutable.empty();
IntInterval.oneTo(100).forEach(i -> squares.put(i, i * i));// Traditional collections (with boxing overhead)
List<Integer> boxedList = new ArrayList<>();
for (int i = 0; i < 1000000; i++) {
boxedList.add(i); // Creates Integer objects
}
// Primitive collections (no boxing)
MutableIntList primitiveList = IntLists.mutable.empty();
for (int i = 0; i < 1000000; i++) {
primitiveList.add(i); // Direct primitive storage
}The primitive collections API provides significant memory and performance benefits by eliminating autoboxing overhead while maintaining the rich functional programming capabilities of Eclipse Collections.
Install with Tessl CLI
npx tessl i tessl/maven-org-eclipse-collections--eclipse-collections-api