This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LinkedHashMap - trying to use the method removeEldestEntry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "LinkedHashMap - trying to use the method removeEldestEntry" Watch "LinkedHashMap - trying to use the method removeEldestEntry" New topic
Author

LinkedHashMap - trying to use the method removeEldestEntry

Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
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
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedHashMap - trying to use the method removeEldestEntry
 
Similar Threads
Nested Layout Managers?
2D array: Find an array of characters
TreeSet should output in ascii order?
java.lang.IllegalStateException: Cannot forward after response has been committed
My head is about to explode!