java中HashMap的基本⽅法使⽤遍历,添加词,等等
房地产买卖合同package test;
插座开关品牌排行前十名
import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Set;
public class test6 {
一平方千米等于多少米public static void main(String[] args) {
莎士比亚十四行诗HashMap<String,Integer> map =new HashMap<>();
map.put("a", 1);赏心悦目造句
map.put("b", 2);
map.put("c", 3);
map.put("d", 4);
// Map map=new HashMap();
// map.put("a", "aaa");
// map.put("b", "bbb");
// map.put("c", "ccc");
// map.put("d", "ddd");
//hashMap遍历⽅法1
Iterator<String> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
船的英文Object key = ();
System.out.println("(key) is :"+(key));
}
//遍历⽅法2
Set<Map.Entry<String, Integer>> Set();
Iterator<Map.Entry<String, Integer>> it=t.iterator();
while(it.hasNext()){
//System.out.(0) );
Map.Entry<String, Integer> ();
System.out.Key()+":"+e.getValue());
}
System.out.ainsValue(1) );
System.out.ainsKey("a") );郁金香白色
System.out.println(map.size() );
System.out.ve("a") );
System.out.println(map.size() );
System.out.ainsKey("a") );
System.out.ainsValue(1) );
//ArrayList <Integer> list =(ArrayList<Integer>)map.values();
//上⾯会出现异常,因为map.values()返回的是⼀个Collection<Integer>对象,可⽤下⾯的⽅法解决
ArrayList <Integer> list =new ArrayList<Integer>(map.values());
Iterator <Integer>ite=list.iterator();
while(ite.hasNext()){
//System.out.(0) );
System.out.() );
}胡萝卜素的功效
map.clear();
System.out.println(map.isEmpty() );
}
}