1.一种效率较高的HashMap遍历方法:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
2.余弦相似度计算:
3.使用HashMap来存储两个向量,并计算其余弦相似度:
public class Similarity {
public static float computeSim(HashMap<String,Float> map1,HashMap<String,Float> map2){
float result = 0;
Iterator iter1 = map1.entrySet().iterator();
Iterator iter2 = map2.entrySet().iterator();
Float sum1 = (float)