wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Linked List and Linked Hash Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Linked List and Linked Hash Map" Watch "Linked List and Linked Hash Map" New topic
Author

Linked List and Linked Hash Map

Ashu Jain
Ranch Hand

Joined: Feb 24, 2008
Posts: 73
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

Joined: Aug 03, 2008
Posts: 9303
    
  17

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.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Linked List and Linked Hash Map