package chn.lass.liu.collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class MapTest {
public static Map<String,String> createMap(){
Map<String,String> map=new HashMap<String, String>();
map.put("a", "111");
map.put("b", "222");
return map;
}
public static void parseMap(Map<String,String> map){
for(Iterator it=map.entrySet().iterator();it.hasNext();){
Map.Entry entry=(Map.Entry)it.next();
System.out.println("key="+entry.getKey());
System.out.println("value="+entry.getValue());
if("a".equals(entry.getKey())){
it.remove();
}
}
for(Iterator it=map.entrySet().iterator();it.hasNext();){
Map.Entry entry=(Map.Entry)it.next();
System.out.println("key1="+entry.getKey());
System.out.println("value1="+entry.getValue());
}
}
public static void main(String[] args) {
Map<String,String> map=createMap();
parseMap(map);
}
}
package chn.lass.liu.collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListTest {
public static List<String> createList(){
List<String> list=new ArrayList<String>();
for(int i=0;i<5;i++){
list.add(""+i);
}
return list;
}
public static void ParseList(List<String> list){
for(Iterator it=list.iterator();it.hasNext();){
String its=(String)it.next();
System.out.println("list is:"+its);
it.remove();
}
}
public static void main(String[] args) {
List<String> list=createList();
ParseList(list);
}
}
package chn.lass.liu.collection;
import java.util.Iterator;
import java.util.Vector;
public class VectorTest {
public static Vector<String> createVector(){
Vector<String> vector=new Vector<String>();
vector.addElement("aa");
vector.addElement("bb");
return vector;
}
public static void parseVector(Vector<String> vector){
for(Iterator it=vector.iterator();it.hasNext();){
String its=(String)it.next();
System.out.println("its is:"+its);
}
}
public static void main(String[] args) {
Vector<String> vector=createVector();
parseVector(vector);
}
}
package chn.lass.liu.collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class SetTest {
public static Set<String> createSet(){
Set<String> set=new HashSet<String>();
set.add("a");
set.add("b");
return set;
}
public static void parseSet(Set<String> set){
for(Iterator it=set.iterator();it.hasNext();){
String its=(String)it.next();
System.out.println("its is:"+its);
}
}
public static void main(String[] args) {
Set<String> set=createSet();
parseSet(set);
}
}