81,092
社区成员
发帖
与我相关
我的任务
分享
public class MemoryCard {
private static Map<String, AccountCache> caches = new HashMap<String, AccountCache>();
/**
* 存入缓存
* @param key
* @param cache
*/
public void putCache(String key, AccountCache accountCache) {
caches.put(key, accountCache);
}
/**
* 获取对应缓存
* @param key
* @return
*/
public AccountCache getCacheByKey(String key) {
if (caches.containsKey(key)) {
return caches.get(key);
}
return null;
}
}
for (String key : caches.keySet()) {
if (key.equals("key1")) {
String value1 = caches.get(key1).toString();}
if (key.equals("key2")) {
String value2 = caches.get(key2).toString();}
}
AccountCache ac = getCacheByKey("key1");
putCache("key1", ac);
ac = getCacheByKey("key2");
putCache("key2", ac);
AccountCache ac = getCacheByKey("key1");
putCache("key1", ac);
ac = getCacheByKey("key1");
putCache("key2", ac);