• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting values from linkedHashMap

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic