hopia
hopia

Reputation: 5006

Is there an equivalent of Android's LRUCache in Java?

I would like to use Android's LruCache in my plain old non-Android Java projects. Is there an equivalent data structure in regular Java or do I have to roll out my own implementation?

Upvotes: 0

Views: 108

Answers (1)

Matt Timmermans
Matt Timmermans

Reputation: 59204

In regular Java you can do it with a LinkedHashMap, using the 3-argument constructor to make it access-ordered, and overriding removeEldestEntry to expire entries.

Upvotes: 1

Related Questions