Map: //HashMap遍历
public static String getMapByEntry(HashMap<String, Integer> hmap) {
StringBuffer keywords = new StringBuffer();
String numStr ="";
//用Set对象打印结果
Set<Map.Entry<String,Integer>> enterySet = hmap.entrySet();
for (Map.Entry<String, Integer> ent : enterySet) {
keywords.append(ent.getKey() + " " + ent.getValue()+ "\n");
}
return keywords.toString();
}
另一种写法
for(String key : conditions.keySet()){
if (key.equalsIgnoreCase("priceLowerBound")) {
int priceLowerBound = Integer.parseInt(conditions.get(key));
if (priceLowerBound > 0)
hql.append(" and p.price > :priceLowerBound");
}
//Other conditions omitted
}
其他参见
http://blog.youkuaiyun.com/avius/archive/2004/07/29/55368.aspx