LinkedHashSet
, for the intents and purposes of being accessed using contains
is simply a hash set. It uses the return from hashCode
of the objects inserted in it to determine the position to place it in in the hash set. If you have a collision, then it will then check the next element. If that is occupied, it will then check the one after that, and so forth. Therefore, for hash sets with relatively small capacity or types which do not return distinguishable hashCode
values, you will see up to O(n)
complexity for insertion or checking the esistence of an item in the hash set. However most times you don't see collisions and so in most cases it will be O(1)
.
Combine this with a O(n)
operation on all entires in your ArrayList
, and you end up with O(n)*O(1)
complexity on average or O(n)
. However if the hashCode()
does not properly distinguish values or if the capacity is small for the LinkedHashSet
, you may see up to O(n*m)
complexity (O(n)*O(m)
) where n is the number of elements in your ArrayList
and m being the number of elements on average in each LinkedHashSet
.
Hope that answers your question!