Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading the elements in HashMap

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Treemap
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic