views:

53

answers:

2

I'm trying to simulate a directly mapped cache in java. Any ideas on which data structure to use to represent the cache?

+1  A: 

Try a Map interface for the reference type and WeakHashMap as the implementation:

int initialCapacity = 1024;    
Map<K, V> cache = new WeakHashMap<K, V>(initialCapacity);
duffymo
A: 

It sounds like you're talking about hardware caching. Would a Map<Long, Byte[]> work?

Matt Ball