• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Fastest iteration

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does LinkedHashMap provide faster iteration than HashMap?

Thanks!
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maps don't provide iteration directly. Is this a trick question?

Bu.
 
Neha Bhattad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question was because of a solution from K&B master test. It states:
LinkedHashSet provides the fastest iteration through a set where you care about the order in which entries were added.

Also K&B book page 608 states:
HashMap - fastest updates (key/value pairs)
LinkedHashMap - Faster iterations.

Q: If i need a map where I need fast access - is LinkedHashMap the answer?

Hope I am clear in my explanation...
Thanks!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LinkedHashMap combines a LinkedList and a HashMap. The main purpose of LinkedHashMap is if you need a Map data structure, and you need to know the order of the key-value pairs in the map. A normal Map does not store its elements in a particular order, but LinkedHashMap uses a LinkedList to keep track of the order of the key-value pairs.

I would just use regular HashMap unless I had some specific requirement to keep track of the order of the key-value pairs in the Map.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic