The example in this article describes how Java uses the HashMap cache to save data. Share to everyone for your reference, specific as follows:
Private static final Hashmap<long, xxx> scache = new Hashmap<long, xxx> ();
private static int sId =-1;
public static void Initalbumartcache () {
try {
//...
if (id!= sId) {
clearcache ();
SId = ID;
}
} catch (RemoteException e) {
e.printstacktrace ();
}
}
public static void ClearCache () {
synchronized (scache) {
scache.clear ();
}
}
public static XXX getcachedxxx (Long Index, bitmapdrawable defaultbitmap) {
XXX d = null;
Synchronized (Scache) {
d = scache.get (Index);
}
if (d = = null) {
//...
synchronized (sartcache) {
//The cache may have changed since we checked
XXX value = Scache.get (Index);
if (value = = null) {
scache.put (Index, D);
} else {
d = value;
}
}} return D;
}
More about Java algorithms Interested readers can view the site topics: "Java data structure and algorithms tutorial", "Java Operation DOM node skills summary", "Java file and directory operation tips Summary" and "Java Cache operation Tips"
I hope this article will help you with Java programming.