Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Linked List and Linked Hash Map  RSS feed

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

K&B says that Linked list is efficient if frequent insertions are required because elements are not shifted as in array. On the other hand says that LinkedHashMap can be slightly slower than hashmap when i comes to adding,removing or finding entries.

I am unable to understand this? As both LinkedList and LinkedHashMap implemented as doubly linked list then why LinkedHashMap is slow when it comes to frequent additions.

-Ashu
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well LinkedList is faster than ArrayList in terms of insertion and deletion. This is because ArrayList maintains indexed list of elements which is ordered according to insertion order.

LinkedHashSet is slower than HashSet in terms of insertion and deletion as HashSet is extremely fast as it doesn't maintain any index or ordering.

So actually LinkedList and LinkedHashSet are equally efficient. It's just that ArrayList is slow in insertion and deletion and HashSet is extremely efficient in terms of Insertion and deletion.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!