EC by Example: Filtering

Learn how to filter a collection using Eclipse Collections.

Filtering: Include or Exclude?

If you have a single method named filter, how do you know if it is supposed to be an inclusive or exclusive filter? In Eclipse Collections, there are two filtering methods named and .

Filtering an Object List

Filtering a primitive List

What other types support Select and Reject?

The Symmetric Sympathy is strong with and .

Select and Reject is available across many types and concerns

Possible to filter both inclusively and exclusively in one iteration?

Yes. There is a method called partition. I will show in the next blog in this series.

APIs covered in the examples

  1. (Eager, Lazy and Parallel) — filters including elements that match a condition
  2. (Eager, Lazy and Parallel) — filters excluding elements that match a condition
  3. — Creates a
  4. — Creates an
  5. — Creates a
  6. — Creates an
  7. — Returns a or
  8. — Returns a
  9. — Converts the target into a

Eclipse Collections is open for contributions. If you like the library, you can let us know by starring it on GitHub.

Java Champion. Creator of the Eclipse Collections OSS Java library ( Inspired by Smalltalk. Opinions are my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store