• 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

LinkedHashMap - trying to use the method removeEldestEntry

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The program compiles but without using "removeEldestEntry", I am not sure if it should be inheriting a size() from HashMap, or whether I need to implement one, and if so what it should contain.
Perhaps I also need a different constructor for the LinkedHashMap. I have searched the ranch and web I have not found a clear example.

I think it should get called automatically from the put method on line 21.



Many thanks!
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've worked it out - though not 100% clear as to how it works. It appears the method needs to be within the constructor of LinkedHashMap.
Also the third argument in the constructor pertaining to the sort order has to be false.

Working version that keeps the last five entries only:



Any further tips appreciated! thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic