Why another collections library?
The Java libraries included basic Hashtable, Stack and Vector collections classes from the beginning. With Java 2, the addition of the Collections Library increased the variety of collections dramatically, as well as offering improved performance in some areas. Even with the improved support in Java 2, though, there's still reason to use alternatives to the standard library classes for high-performance applications.
Performance and clarity benefits
The 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 ints, you need to create an object wrapper for each value added to the collection. This causes considerable overhead both when initially adding values and when accessing the values later, since you have to first cast the object reference to the appropriate type and then retrieve the actual value.
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 Integer objects and generic collections. For primitive int values in a type-specific collection the performance increase is much greater, to almost 4 times that for the Integers in a standard IntArray.
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.
其他Java Java Collections集合工具 开源项目资源: