title: How to test if a Java iterator always uses the same order (reproducible ordering)?
body: <p>I have a code in which for-each-loops on a Set need to rely on the fact that the iterator returns the elements always in the same order, e.g.</p>
  
  <p><code>
  for(ParameterObject parameter : parameters) {
    /* ... */
  }
  </code></p>
  
  <p>The iterators returned by <code>HashSet</code> are not guaranteed to have this property, however it is documented that the iterators of <code>LinkedHashSet</code> do have this property. So my code uses a <code>LinkedHashSet</code> and everything works fine.</p>
  
  <p>However, I am wondering if I could endow the my code with a check that the set passed to it conforms to the requirement. It appears as if this is not possible (except of a direct test on <code>LinkedHashSet</code>). There is no interface implemented by <code>LinkedHashSet</code> which I could test on and there is no interface implemented by <code>LinkedHashSet.iterator()</code> which I could test on. It would be nice if there is an interface like <code>OrderConsistentCollection</code> or <code>OrderConsistentIterator</code>.</p>
  
  <p>(I need this property <a href="http://svn.finmath.net/finmath%20lib/trunk/src/main/java/net/finmath/marketdata/calibration/ParameterAggregation.java" rel="nofollow">here</a>). </p>