• Post Reply Bookmark Topic Watch Topic
  • New Topic

LinkedHash Map-Ordering garentee  RSS feed

 
Bala'J'i Rags
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using a LinkedHashMap to save the key-value pairs in the order in which they were inserted.There are scenarios when i use LinkedHashMap's keySet() method to iterate the Map,so when we use the KeySet() method which returns the Set object,is their a garuntee that the returned Set objects contains the keys in the order in which it was in the Hashmap(insertion order).Are there any performance issue in using the same??Please suggest and advice..


Thanks!
[ November 09, 2008: Message edited by: Bala'J'i Rags ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key set is in insertion order, yes. Not sure what sort of performance issue you're thinking of here, but no special ones associated with the keySet() method.
 
Bala'J'i Rags
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest..I was concerned about the performance issue in using a Linked HashMap instead of HashMap (memory usage as well as the Speed factor of retreiving and inserting data into the Map)
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For any Map implementation, keySet(), entrySet() and values() return a view on the original Map. This means that additions to the Map are also noticable in these collections, and the order is always the same as that of the Map.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!