This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linked List and Linked Hash Map

 
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: 9527
32
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic