removeEldestEntry
如何在
FileOutputStream
,DataOutputStream
和writeObject()
的帮助下覆盖removeEldestEntry
方法将最长的条目保存到文件中。码。
这是一个例子:
import java.util.*;
public class level1 {
private static final int max_cache = 50;
private Map cache = new LinkedHashMap(max_cache, .75F, true) {
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > max_cache;
}
};
public level1() {
for (int i = 1; i < 52; i++) {
String string = String.valueOf(i);
cache.put(string, string);
System.out.println("rCache size = " + cache.size() +
"tRecent value = " + i + " tLast value = " +
cache.get(string) + "tValues in cache=" +
cache.values());
}
没有找到相关结果
已邀请:
2 个回复
薄扩络拜
昧伎
如果删除了某个项目,请打开OutputStream 写出对象 从超级调用返回布尔值。