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