Skip to content
Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.
Java HTML Scala
Branch: master
Clone or download
donraab Merge pull request #736 from TheLoneKing/master
Implement RichIterable.groupByAndCollect(). Resolves #47
Latest commit a1e4c6b Sep 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Refresh IntelliJ project files to remove commons-codec. Jan 20, 2019
.mvn Add .mvn/maven.config with options --show-version and --errors. Jul 27, 2018
acceptance-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
artwork Add Eclipse Collections logo. Aug 20, 2017
docs Implement #657: Documentation: Examples for Immutable Collections. Sep 15, 2019
eclipse-collections-api Implement RichIterable.groupByAndCollect(). Resolves #47 Sep 17, 2019
eclipse-collections-code-generator-maven-plugin Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
eclipse-collections-code-generator Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
eclipse-collections-forkjoin Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
eclipse-collections-testutils Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
eclipse-collections Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
jcstress-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
jmh-scala-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
jmh-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
junit-trait-runner Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
missing-dependency Sync IntelliJ project files for TeamCity. Aug 3, 2018
p2-feature Ignore Eclipse configuration file Nov 18, 2018
p2-repository Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
performance-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
scala-unit-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
serialization-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
site Prepare for 10.0.0 release. Jul 11, 2019
test-coverage Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
unit-tests-java8 Implement RichIterable.groupByAndCollect(). Resolves #47 Sep 17, 2019
unit-tests Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
.gitattributes Initial import. Dec 9, 2015
.gitignore Refresh IntelliJ project files to remove commons-codec. Jan 20, 2019
.travis-command-ea-builds.sh Remove redundant parts of Travis custom script for EA builds. Feb 6, 2019
.travis.yml Upgrade maven from 3.5.2 to 3.6.1. Upgrade maven plugins: Jul 11, 2019
CONTRIBUTING.md Update Contributor License information with latest ECA. Sep 14, 2016
LICENSE-EDL-1.0.txt Initial import. Dec 9, 2015
LICENSE-EPL-1.0.txt Initial import. Dec 9, 2015
README.md Prepare for 10.0.0 release. Jul 11, 2019
RELEASE_NOTE_DRAFT.md Prepare for 10.0.0 release. Jul 11, 2019
about.html Add about.html and license files for documentation within the release… Dec 24, 2015
checkstyle-configuration.xml Turn on additional CheckStyle rules and fix violations. Sep 12, 2018
checkstyle-suppressions.xml Fix broken CheckStyle build and static analysis violations. Jul 13, 2018
deploy.properties Initial import. Dec 9, 2015
eclipse-collections-parent.iml Sync IntelliJ project files for TeamCity. Aug 3, 2018
findbugs-exclude.xml Implement countBy and countBy with target as default methods on RichI… Jun 24, 2017
java.header Remove executable bit from files that are not executable Nov 17, 2016
pom-template Fix GitHub url in pom files. Dec 10, 2015
pom.xml Update version number to 10.1.0-SNAPSHOT. Jul 12, 2019
version.properties Remove executable bit from files that are not executable Nov 17, 2016

README.md

English | 中文 | Deutsch | Français | 日本語 | Português-Brasil | Русский

Eclipse Collections is a comprehensive collections library for Java. The library enables productivity and performance by delivering an expressive and efficient set of APIs and types. The iteration protocol was inspired by the Smalltalk collection framework, and the collections are compatible with the Java Collection Framework types.

Why Eclipse Collections?

  • Productivity
    • Rich, functional, and fluent APIs with great symmetry
    • List, Set, Bag, Stack, Map, Multimap, BiMap, Interval Types
    • Readable, Mutable, and Immutable Types
    • Mutable and Immutable Collection Factories
    • Adapters and Utility classes for JCF Types
  • Performance
    • Memory Efficient Containers
    • Optimized Eager, Lazy and Parallel APIs
    • Primitive Collections for all primitive types
  • Actively developed since 2005

Learn Eclipse Collections

Acquiring Eclipse Collections

Maven

<dependency>
  <groupId>org.eclipse.collections</groupId>
  <artifactId>eclipse-collections-api</artifactId>
  <version>10.0.0</version>
</dependency>

<dependency>
  <groupId>org.eclipse.collections</groupId>
  <artifactId>eclipse-collections</artifactId>
  <version>10.0.0</version>
</dependency>

Gradle

compile 'org.eclipse.collections:eclipse-collections-api:10.0.0'
compile 'org.eclipse.collections:eclipse-collections:10.0.0'

OSGi Bundle

Eclipse software repository location: http://download.eclipse.org/collections/10.0.0/repository

Some Quick Examples

Eclipse Collections puts iteration methods directly on the container types. Here's several code examples that demonstrate the simple and flexible style of programming with Eclipse Collections.

First, we will define a simple class named Person to hold the first and last names of three people.

public class Person
{
    private final String firstName;
    private final String lastName;

    public Person(String firstName, String lastName)
    {
        this.firstName = firstName;
        this.lastName = lastName;
    }
    ...
    public String getLastName()
    {
        return this.lastName;
    }
    
    public boolean lastNameEquals(String name)
    {
        return name.equals(this.lastName);
    }
}

Collect (aka map, transform)

Now we will create a MutableList with three instances of the Person class. Then we will collect their last names into a new MutableList, and finally output the names to a comma delimited String using makeString.

MutableList<Person> people = Lists.mutable.with(
        new Person("Sally", "Smith"),
        new Person("Ted", "Watson"),
        new Person("Mary", "Williams"));
MutableList<String> lastNames = people.collect(person -> person.getLastName());
Assert.assertEquals("Smith, Watson, Williams", lastNames.makeString());

The lambda in the example above can also be replaced with a method reference.

MutableList<String> lastNames = people.collect(Person::getLastName);

Eclipse Collections has support for both Mutable and Immutable collections, and the return types of methods are covariant. While the collect method on a MutableList returned a MutableList, the collect method on an ImmutableList will return an ImmutableList. Here we use the same Lists factory to create an ImmutableList.

ImmutableList<Person> people = Lists.immutable.with(
        new Person("Sally", "Smith"),
        new Person("Ted", "Watson"),
        new Person("Mary", "Williams"));
ImmutableList<String> lastNames = people.collect(Person::getLastName);
Assert.assertEquals("Smith, Watson, Williams", lastNames.makeString());

Eclipse Collections has a lazy API as well, which is available by calling the method asLazy. The method collect will now return a LazyIterable. The LazyIterable that is returned does not evaluate anything until the call to a terminal method is made. In this case, the call to makeString will force the LazyIterable to collect the last names.

LazyIterable<String> lastNames = people.asLazy().collect(Person::getLastName);
Assert.assertEquals("Smith, Watson, Williams", lastNames.makeString());

Select / Reject (aka filter / filter not)

We can find all of the people with the last name "Smith" using the method named select.

MutableList<Person> people = Lists.mutable.with(
        new Person("Sally", "Smith"),
        new Person("Ted", "Watson"),
        new Person("Mary", "Williams"));
MutableList<Person> smiths = people.select(person -> person.lastNameEquals("Smith"));
Assert.assertEquals("Smith", smiths.collect(Person::getLastName).makeString());

If we want to use a method reference, we can use the method selectWith.

MutableList<Person> smiths = people.selectWith(Person::lastNameEquals, "Smith");
Assert.assertEquals("Smith", smiths.collect(Person::getLastName).makeString());

We can find all the people who do not have a last name of "Smith" using the method named reject.

MutableList<Person> notSmiths = people.reject(person -> person.lastNameEquals("Smith"));
Assert.assertEquals("Watson, Williams", notSmiths.collect(Person::getLastName).makeString());

If we want to use a method reference, we can use the method rejectWith.

MutableList<Person> notSmiths = people.rejectWith(Person::lastNameEquals, "Smith");
Assert.assertEquals("Watson, Williams", notSmiths.collect(Person::getLastName).makeString());

Any / All / None

We can test whether any, all or none of the elements of a collection satisfy a given condition.

// Any
Assert.assertTrue(people.anySatisfy(person -> person.lastNameEquals("Smith"));
Assert.assertTrue(people.anySatisfyWith(Person::lastNameEquals, "Smith"));

// All
Assert.assertFalse(people.allSatisfy(person -> person.lastNameEquals("Smith"));
Assert.assertFalse(people.allSatisfyWith(Person::lastNameEquals, "Smith"));

// None
Assert.assertFalse(people.noneSatisfy(person -> person.lastNameEquals("Smith"));
Assert.assertFalse(people.noneSatisfyWith(Person::lastNameEquals, "Smith"));

How to Contribute

We welcome contributions! We accept contributions via pull requests here in GitHub. Please see How To Contribute to get started.

Additional information

You can’t perform that action at this time.