• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

LinkedList,LinkedHashSet,LinkedHashMap

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LinkedList,LinkedHashSet,LinkedHashMap are counter part of each other,I think they all have some simlarities.

Simlarites:
1) Insertion order is maintained
2) Elements are doubly linked with each other

In linkedList it mention that it is good choice for insertion and deletion as comapred to any collection in List Interface.
Q1) In LinkedHashSet, Can we say it is good choice for insertion and deletion as comapred to any collection in Map Interface?
Q2) In LnkedHashMap,addtion and deletion is slower as compared to HashMap? Why? I think it must be good choice for insertion
and deletion because elements are doubly linked with one another?






 
Rancher
Posts: 3404
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

amolpalekar kadolkar wrote:Q1) In LinkedHashSet, Can we say it is good choice for insertion and deletion as comapred to any collection in Map Interface?


Um, why would we care about comparing to any Map interface? Maps and Sets do completely different things.

If you meant to ask if it was good or bad compared to other Set interfaces, it's a little slower than a plain HashSet, but pretty fast nonetheless.

amolpalekar kadolkar wrote:Q2) In LnkedHashMap,addtion and deletion is slower as compared to HashMap?



Yes - but it's only a little slower. Use the LinkedHashMap if you actually need the ordering it provides, and don't use it if you don't need it. But if you do need it, don't worry about the fact that it's slightly slower. It usually isn't noticeable.

amolpalekar kadolkar wrote:Why? I think it must be good choice for insertion and deletion because elements are doubly linked with one another?


Well, the hashtable algorithm already provides a very fast way to locate, add, or remove items. The fact that there are also bidirectional links between entries means that you need to spend a little more time setting up those links, in addition to setting up the hashtable.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!