Oracle Blog

A globally warmed, swing focused blog in the Participation Age.

Collections Trick I: LRU Cache

Maybe it's just my job. Or maybe it's just fashion. The fact is that I meet little people
understanding and/or taking advantage of Data Structures and Algorithms. People tend to use
higher-level abstractions (EJBs, JSPs and the like) and usually forget about the low-level
stuff.

I don't mean you have to be an expert on that, but I think it's indeed useful.

So the other day, talking to a customer, I noticed he was trying to build a LRU (least recently used) cache
for whatever it was. And he was in trouble. He didn't know that's already done, and it's well
done.

The fact is that he didn't pay attention to the LinkedHashMap. You do it as follows: