shebelaw
shebelaw

Reputation: 4172

What does it mean to have inherent order?

While going through Collection Mapping in Hibernate. I came accrosse inherent order. What does it mean to have inherent order?

thanks,

Upvotes: 0

Views: 3621

Answers (2)

thedayofcondor
thedayofcondor

Reputation: 3876

Usually, when persisting on a database things as a List, the order of the elements is not preserved (you can preserve it by storing the index in an additional field). The elemnts are retrieved in a different order compared to the insertion order and the List will be shuffled.

However, some data structures have an 'inherent order', for example a TreeMap will be restored with the elements in Comparator order because, no matter on which order you use to retrieve the elements, the TreeMap will restore the order.

Upvotes: 1

Aasmund Eldhuset
Aasmund Eldhuset

Reputation: 37970

It refers to whether the order of the elements in a collection is important or not. A list has inherent order: A list containing [1, 2, 3] is different from a list containing [3, 2, 1]. A set, on the other hand, does not have inherent order: A set containing [1, 2, 3], is the same as a set containing [3, 2, 1] or [2, 1, 3] and so on.

Upvotes: 4

Related Questions