集合


无序集合
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
    public static void main(String[] args) {
        Map map =new HashMap();
        map.put("一阶",1);
        map.put("二阶",2);
        map.put("三阶",3);

        //遍历集合
        Set set=map.keySet();
        //迭代器
        Iterator ter=set.iterator();
        while (ter.hasNext()){
            String k= ter.next();
            Integer v=map.get(k);
            System.out.println(k+v);
        }
        for (String k:set) {
            Integer v=map.get(k);
            System.out.println(k+v);
        }

        //键值对对象遍历
        Set> entry= map.entrySet();
        for (Map.Entry e:entry) {
            System.out.println(e.getKey()+"="+e.getValue());
        }
        Iterator> terr=entry.iterator();
        while (terr.hasNext()){
            Map.Entry entry1=terr.next();
            System.out.println(entry1.getKey()+"="+entry1.getValue());
        }
    }
}
HashMap 有序集合
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class LinkedHashMapDemo {
    public static void main(String[] args) {
        Map map=new LinkedHashMap<>();
        map.put("一阶",1);
        map.put("二阶",2);
        map.put("三阶",3);
        Set> set=map.entrySet();
        for (Map.Entry e:set) {
            System.out.println(e.getKey()+"="+e.getValue());
        }
    }
}
LinkedHashMap集合