package setTest;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class TestMap {
public static void main(String[] args) {
HashMap hm = new HashMap();
hm.put("aa", "test1");
hm.put("bb", "test2");
hm.put("cc", "test3");
hm.put("dd", "test4");
hm.put("ee", "test5");
//iterator
Iterator it = hm.keySet().iterator();
while(it.hasNext()) {
//key
String str = (String)it.next();
System.out.print(str+" ");
//value
String value = (String)hm.get(str);
System.out.println(value);
}
for (Object obj : hm.keySet()) {
String key = (String)obj;
System.out.print(key+" ");
String value = (String)hm.get(key);
System.out.println(value);
}
Set set = new HashSet();
set.add("aa");
set.add("bb");
set.add("cc");
set.add("dd");
for(Iterator it1 = set.iterator();it1.hasNext();) {
String str = (String)it1.next();
System.out.println(str);
}
for(Object obj:set) {
System.out.println(obj);
}
}
}