Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Does LinkedHashSet support last accessed order?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
According to the API only LinkedHashMap supports retrieving elements by their last accessed order.But in the K&B book they say that LinkedHashSet also supports this feature.
Can someone clarify?
Thanx in advance
Alexan
[ July 25, 2003: Message edited by: Alexan Kahkejian ]
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where in the API does it say that only the LinkedHashMap specifies that behavior?
In any case, the LinkedHashSet API also specifies last-accessed order. Maybe LinkedHashMap is the only *Map* collection that supports last accessed functionality.
 
Alexan Kahkejian
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jon
Actually I reached to this conclusion form examining the LinkedHashSet Constructors, if you check them and compare them with LinkedHashMap constructors you will find that LinkedHashSet doesn't include any constructor which have the boolean argument which decides this behavior while LinkedHashMap has the following constructor.

So How to set this behavior to LinkedHashSet?
Alexan
 
Alexan Kahkejian
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
So can someone confirm if LikedHashSet supports last accessed order behavior or not?
Alexan
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So can someone confirm if LikedHashSet supports last accessed order behavior or not?


When in doubt, read the source code.

As you can see from the source code, a LinkedHashSet is backed by a LinkedHashMap with the accessOrder set to false.
Furthermore, there is no public constructor for LinkedHashSet to change the access order from insertion order to access order.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic