Why another collections library?The Java libraries included basic Performance and clarity benefitsThe biggest performance problem with the standard classes is that they only
work with objects, not with primitive types. To build a collection of primitive
values, such as Even with collections of objects, the library classes are not optimized for
performance. Timing measurements listed under the Timings
topic show a better than 20 percent increase in performance using the classes
from this library in a test with In addition, these library classes allow more robust code because no casting of values is required. Casting bypasses the type checking done by the compiler and defers the checking to runtime, when mistakes are generally a lot more painful to catch. Using type-specific collections restores the type checking responsibility to the compiler and assures that errors are caught before they're turned into executing code. Getting rid of the casts also makes your code cleaner and easier to understand. Why not to use these classesThe biggest drawback to type-specific collections is that Java requires tailoring of the code to each type. This library is designed to minimize the effort needed to construct a collection for a type, and comes with unit tests which can easily be adapted to new type-specific variations of the included collections. If you're working with types which aren't included in the library you're still going to need to do extra work to build the collection classes you want, though. If your code is heavily using collections of some particular type the performance and robustness gains may be worth the effort. Before doing this, though, consider if it's possible to use a plain array (the simplest form of type-specific collection!) for your needs. If you can use an array you'll have the best of both worlds - code that offers top performance along with simplicity and ease of use. LicenseTo make it as easy as possible to reuse this code, it has been released as open source code under the liberal MIT License (our specific license is available here). |