• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic