Friday 15 August 2014

java - LinkedHashSet to implement LRU -


I want to delete the oldest member of LinkedHashSet , I know that a The oldest entry method which I want to override (), but I think I have to define the initial capability and load factor which I do not care about And I just want to delete the element which was recently used (even on the basis of access i mean Put when it is already in the set or is reading)

Is there no way override removeEldestEntry ?

I know that I have one deleted entry entry method override

This statement is incorrect because LinkedHashSet has-A LinkedHashMap is no more -A

You can use (though not well known), method:

  set & lt; String & gt; MySet = Collections.newSetFromMap (New Linkedhep & lt; String, Boolean & gt; () Remove the protected Boolean Extra Large Entry (Map. Entry & lt; String, Boolean & gt; largest) {Return size ()> MAX_ENTRIES ;}});   

This is how your custom removeEldestEntry link one linked (a set-similar interface) Code> Method

MAX_ENTRIES Being a custom static that you define.

No comments:

Post a Comment