Wrappers are indeed the preferred solution most of the time. It's also possible to use other collection-like classes which are optimized for specific primitive types. E.g. an array list of ints which uses an int[] array rather than an Object[], eliminating the need for wrappers and a lot of casting. However this is a bit risky, as unless you know what you're doing, it's easy to accidentally write a class which is slower &/or harder to use than the existing collections framework. It's probably not worthwhile trying to develop these yourself - there are already custom implementations floating around. I haven't used them, but the classes at
trove4j.sourceforge.net look like they might be worth trying.
Remember though that by leaving the standard
Java library classes, you're making it harder for other programmers to tell what you're doing or recognize bugs, since they're not nearly as familiar with how these nonstandard classes work. Thuse,
you should probably stick to using wrappers unless you have good reasons for switching.
[ August 25, 2002: Message edited by: Jim Yingst ]