标签:
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Collection;
import java.util.Set;
import java.util.Map;
import java.util.Map.Entry;
public class EXHash
{
public static void main(String[] args){
//Hashset操作
ArrayList ar=new ArrayList();
for (int i=0;i<100;i++)
{
ar.add(i);
}
HashSet hs=new HashSet(ar);
if(hs.contains(5))
{
System.out.println("该set中包含5");
}
Iterator it=hs.iterator();
for (int i=0;i<hs.size();i++)
{
System.out.println(it.next());
}
//HashMap操作
HashMap hm=new HashMap();
hm.put(1,"shdfAh");
hm.put(2,"sdfdfe");
hm.put(3,"8799");
/** System.out.println(hm.size());
Collection ay=hm.values();
Iterator it=ay.iterator();
while(it.hasNext())
{ System.out.println(it.next());}**/
System.out.println(hm.get(4));
Set s1=hm.keySet();
Iterator it=s1.iterator();
for (int i=0;i<s1.size();i++)
{
System.out.println(it.next());
}
Set s2=hm.entrySet();
Iterator it1=s2.iterator();
for (int i=0;i<s2.size();i++)
{
Map.Entry me=(Map.Entry)it1.next();
System.out.println(me.getKey());
System.out.println(me.getValue());
}
}
}
HashSet,HashMap
标签:
原文地址:http://www.cnblogs.com/wuguang/p/4637635.html