Java Interview : LinkedHashSet


LinkedHashSet in Java
LinkedHashSet in Java
2) LinkedHashSet gurantees that its iterator will return the elements in insertion order, that is the order in which they were added in LinkedHashSet, underlying it uses a linkedlist to maintain this order.
3) Fetching the next element is performed in constant time as it uses a linkedlist, but memory might become a constraint if we need to maintain a very large linkedlist.
4) When to use
a)When you do not want duplicate elements in the collection.
b)You want to access the elements in the order in which they were added in  collection.
5) LinkedHashSet maintains a doubly linkedlist, so it is slower for insertion and removal, but is faster for iteration.
6) Iterator returned by LinkedHashSet is fail-fast, thus if the collection is changed while iteration it will throw a ConcurrentModificationException.
7)  LinkedHashSet is not thread-safe.
8) LinkedHashSet allows null


LinkedHashSet Performance
LinkedHashSet Performance

Comments

Popular posts from this blog

Java Interview : Threads

Spring Framework Interview Notes : Part Two Wiring

Card Dealer In Java in Less than 5 minutes