HashMap基本用法
IT技术
HashMap是java的常用的容器,它按照KEY=VALUE格式保存数据 使用起来非常简单,使用put(key,value)将数据保存在map中 使用get(key)获取对应的值,如果没有返回NULL 如果要遍历所有的值,首先使用keySet获取全部的key的集合,然后获取key集合的迭代,使用迭代遍历全部的key就行了
一个很简单的例子。 import java。util。*; class HashMapDemo { public static void main(String args[]) { //生成一个HashMap HashMap hm = new HashMap(); // 把元素加到HashMap里面 hm。
put("John Doe", new Double(3434。34)); hm。put("Tom Smith", new Double(123。22)); hm。put("Jane Baker", new Double(1378。00)); hm。
put("Todd Hall", new Double(99。22)); hm。put("Ralph Smith", new Double(-19。08)); // 从HashMap 里面取出一个集合。 Set set = hm。entrySet(); // 生成一个迭代 Iterator i = erator(); // 显示刚才放进去的东西。
while(i。hasNext()) { Map。Entry me = (Map。Entry) xt(); int( tKey() + ": "); intln( tValue()); } intln(); // 再放1000到John Doe的帐户里面。
double balance = ((Double) t("John Doe"))。doubleValue(); hm。put("John Doe", new Double(balance + 1000)); // 再看看结果。 intln("John Doe's new balance: " + t("John Doe")); } } 。
答:这个简单,你用jquery, 当在一个文本框失去焦点后,通过$.post(url,param,function(data){});去修改服务器的库存,并用jqu...详情>>