146. LRU Cache
2016-05-04 15:22
211 查看
在写代码前看了两篇博客才大概理解了java中的hashmap和linkedhashmap
http://zhangshixi.iteye.com/blog/673789
http://zhangshixi.iteye.com/blog/672697
http://zhangshixi.iteye.com/blog/673789
http://zhangshixi.iteye.com/blog/672697
import java.util.HashMap; import java.util.LinkedHashMap; public class LRUCache extends LinkedHashMap<Integer,Integer>{ private int maxcapacity; public LRUCache(int capacity) { super(capacity,0.75f,true); this.maxcapacity=capacity; } public int get(int key) { Integer vaule=super.get(key); if(vaule==null)return -1; else return vaule; } public void set(int key, int value) { super.put(key,value); } protected boolean removeEldestEntry(Map.Entry<Integer,Integer> eldest) { return size()>maxcapacity; } }
相关文章推荐
- HttpClient异步,及连接池应用
- 分享一个Java和Android学习视频
- tp框架中使用phpexcel导出excel表格
- ORACLE获取数据的物理地址
- .Net C#(类的继承/虚函数/抽象函数/密封类/静态类/抽象类)——学习笔记
- 端口占用
- 避免直接依赖 android log 库
- hdu 2126 Buy the souvenirs 01背包
- 列表头部放大效果的图
- 为什么#pragma once不在C++11标准里?
- JVM(Java虚拟机)优化大全和案例实战
- 【华为OJ】【010-字符个数统计】
- c++ 子类调用父类构造方法 调用父类方法 类声明与实现分离
- DOS命令:IIS安装与卸载
- 诊断篇(5.2) 01. 接口故障排查 ❀ 飞塔 (Fortinet) 防火墙
- BroadCastReceiver详解
- JavaScript获取浏览器类型与版本
- 如何禁用防火墙激活CleanMyMac 3
- 浅析CSS等高布局的6种方式
- java中数组