liveBook · Manning

FastUtil

As explained in 100 Java Mistakes and How to Avoid Them

FastUtil is a Java library providing high-performance collections specialized for primitive and other commonly used types.

FastUtil is a Java library for specialized primitive collections. It avoids boxing, reduces memory use, and provides operations that accept primitive values directly, helping prevent confusing comparisons between boxed types such as Integer and Short. section 8.1

FastUtil is useful when ordinary boxed collections create these risks:

  • A search compares values whose boxed runtime types differ, so a logically expected match is not found. section 8.1
  • List.remove() binds to removal by index when the intended operation was removal by value. section 8.9
  • Separate removal-by-value and removal-by-index method names make the intended operation clearer, while successful value removal can be checked explicitly. section 8.9

Prefer primitive-aware collection operations

With a boxed collection, offsets.remove(0) may remove the element at index 0 rather than the value 0. A cast such as offsets.remove((Integer) 0) makes value removal explicit, while FastUtil provides separate method names for these operations and avoids primitive boxing. section 8.9

List<Integer> offsets = getOffsets();
offsets.remove(0);

Inspect the minimal List.remove example that exposes the ambiguity between an index argument and a value argument. section 8.9

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains the practical benefits and relevant failure modes but stops short of installation, API coverage, or implementation internals.
Examples
Uses mismatched boxed-type searches and List.remove(0) versus remove((Integer) 0) to motivate primitive collections.
What it assumes
Assumes familiarity with Java collections, boxed primitive types, contains, remove, and overloaded methods.
What you can do after
Apply FastUtil to avoid boxing-related comparisons and make collection removal intent explicit.
How it connects
Connects primitive collections with boxing, Java collections, method overloading, collection search, and static analysis.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.