On Tuesday 29 April 2008, Fred Dushin wrote: > Is there a reason hashed collections are used, almost exclusively, in > CXF? Even in cases where collections are predictably small, > Hash(Maps| Sets) almost always win out over their sortable cousins in > the java.util namespace, and this, even when the keys are sortable. > > Is there a technical reason for this? A personal preference?
Depends on the location in the code. One reason for using a hash based map is that there exists the ConcurrentHashMap that is a drop in replacement when thread concurrency is required. Likewise, there is a CopyOnWriteArrayList for the ArrayList flip. There aren't any conncurrent versions of the SortedSet/Map things. (they were added in Java 1.6, but not available in Java 1.5) > I've done some performance comparisons between the 2, and for small > collections, the log(n) lookup doesn't make a difference at all. So > for small collections, I'd think CXF might benefit from the relatively > smaller memory footprint of sortable collections. We'd also benefit > from more predictable behavior, as ordering is deterministic, with > sortable collections. > > The same goes for ArrayLists vs LinkedLists, BTW. Actually, that really does depend. In most cases, and ArrayList uses less memory than a LinkedList, especially if we set a "smart" initial size. > Just wondering... Probably just preference and maybe a small bit of "consistency" thrown in for good measure. -- J. Daniel Kulp Principal Engineer, IONA [EMAIL PROTECTED] http://www.dankulp.com/blog