I am looking for a way to find out in run-time, whether a collection is ordered or not. Any way to do this?
EDIT: I am sorry for wrongly asked question. I meant whether there is some general way to say HashMap does not store order of elements being inserted, where LinkedHashMap does.
For elements that implement the
Comparableinterface, you can check to see if they are in their “natural” order.Otherwise, you’ll have to define a
Comparatorthat can compare your objects according to your definition of order, and pass that to the test.