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
