File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 9280
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linked List and Linked Hash Map
 
Similar Threads
K&B Java 5 scjp ch7 page 24/114
Question on a Mock Exam Question
collections framework
java Collections
Java Collections - Internal Working