Hi,

I would like to advertize the usage of java.util.LinkedHashMap and
java.util.LinkedHashSet. Unlike their close relatives HashMap and HashSet,
the former two collection classes offer a deterministic iteration order of
their elements by keeping the insertion order.

In general, clients will be happy if code retains the order of elements when
processing collections instead of messing them up. A prominent example from
the Maven Core is the following idiom:

 List input = ...;
 Map temp = new LinkedHashMap();
 for ( Iterator it = input.iterator(); it.hasNext(); )
 {
    temp.put( <some-key>, it.next() );
 }
 List output = new ArrayList( temp.values() );

Using HashMap in those cases would yield indeterministic ordering in the
output collection. If one is dealing with artifacts, this means messing up
the class path.

So please think twice whether HashSet/HashMap are really sufficient or
whether there exists the smallest possibility that some client code might
depend on the proper/deterministic ordering.

Regards,


Benjamin


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to