Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedHashSet is an ordered set

 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading a book that says a LinkedHashSet is an ordered set.
We call a set sorted (SortedSet) when the iterator returns the elements sorted. So I suppose we can call a set ordered when the iterator returns the elements in some predictable order.
We know that a List is an ordered collection. We know that two instances of a List are *equal* if they contain the same elements *in the same order*.
However, two instances of a LinkedHashSet are equal if they contain the same elements, although the elements might not be in the same order.
The order is essential to the identity of a List instance. The order is not essential to the identity of a LinkedHashSet instance.
Saying a List is an ordered collection is different in degree from saying that a LinkedHashSet is an ordered set.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic