This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes getting values from linkedHashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "getting values from linkedHashMap" Watch "getting values from linkedHashMap" New topic
Author

getting values from linkedHashMap

kavuri
Greenhorn

Joined: Sep 30, 2008
Posts: 2
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

Joined: Feb 25, 2007
Posts: 1638

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 ]

apigee, a better way to API!
Maurizio Nagni
Ranch Hand

Joined: May 29, 2004
Posts: 75
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: getting values from linkedHashMap
 
Similar Threads
Need to store the result obtained within a while loop for further usage
JSON+Jquery
Doubt in HashMap
ordering of elements in Hashtable
What to lock if I want to allow multi-thread access different keys in the LinkedHashMap