JavaSE student

HashSetDemo实现

import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;

public class LinkedHashedSet {
    public static void main(String[] args) {
        HashMap  hs = new HashMap();
         hs.put(1, "李渊");
         hs.put(2,"李元芳");
         hs.put(3, "王羲之");
         hs.put(4, "王莽");
        //移除数据
        String s1 =  hs.remove(2);
        System.out.println(s1);
        //遍历map,得到所有的key
        Set a = hs.keySet();
        for(Integer key : a) {
            System.out.println(hs.get(key));
        }
        //获得所有的values
        Collection q = hs.values();
        for(String ss : q) {
            System.out.println(ss);
        }
        //获得entryset集合 并循环取出
        Set> b = hs.entrySet();
        for( Entry e: b) {
            System.out.println(e);
        }
    }
}

你可能感兴趣的:(JavaSE student)