wood burning stoves 2.0*
The moose likes Java in General and the fly likes reading the elements in HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "reading the elements in HashMap" Watch "reading the elements in HashMap" New topic
Author

reading the elements in HashMap

sitaram irrinki
Ranch Hand

Joined: Feb 16, 2005
Posts: 158
How to access the elments of a HashMap in the insertion order.Whenever we
access the elements in a hashMAp we get some order based on the Hashcode,but
how to get the elemnts in insertion order
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
The java.util package provides the LinkedHashMap if you need iteration in order of insertion.
If you have the space, you really should have the complete JavaDocs unpacked on your hard drive for quick answers to questions like this.
Bill
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
Treemap
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Not TreeMap - that sorts items by some sort of ordering provided either by the key object "natural order" or by a user provided comparator.
Only LinkedHashMap gives you iteration of keys or entries by insertion order.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading the elements in HashMap
 
Similar Threads
is LinkedHashSet ordered?
LinkedHashSet
Collection
Enumeration of elements in key Insertion order for java.util.Properties
Maintaining order in the map