• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting values from linkedHashMap  RSS feed

 
kavuri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a scenario in my project where i need a collection which don't accept dulicate values and orderd.Then i apparently went for LinkedHashMap.But while i getting values from map i used map.keySet() to get the keys.Thst keys were unordred as set was unordered.
How can we get the values from LinkedHashMap in insertion order
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy "vamsi"!

Welcome to javaranch!
We being a very friendly community, do not have much rules but there is a naming policy that we are very strict about!
Unfortunately, your display name does not follow the policy. Please change the same according to our policy.

How can we get the values from LinkedHashMap in insertion order

Are you sure that you did not get the keys in the insertion order?
By any chance, have you used this constructor with the last argument as "true". If yes, then the map will have entries in the access order.
[ October 15, 2008: Message edited by: Nitesh Kant ]
 
Maurizio Nagni
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Vamsi,

could you please better explain your task? You say
1)
i need a collection which don't accept dulicate values and orderd

......in this case ordering is a property given by the Comparable interface

2)
How can we get the values from LinkedHashMap in insertion order

...... in this case LinkedHasMap work as you ask (anyway same key will remain in the same position not promoted in a higher position)

so, before of all, which are your needs?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vamsi:
I have a scenario in my project where i need a collection which don't accept dulicate values and orderd.Then i apparently went for LinkedHashMap.


Actually, this sounds like you might want to use a LinkedHash*Set* instead.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!