第二题,第三题

第二题:

package Zuoye1;

import java.util.*;;

public class SetList {

    public static void main(String[] args) {
        
        
        List<String> l=new ArrayList<String>();
        l.add("A");
        l.add("a");
        l.add("C");
        l.add("c");
        l.add("a");
        for(String s:l)
        {
            System.out.println(s);
        }
        
        
        System.out.println("Lise能成功添加");
        Set<String> sh=new HashSet<String>();
        sh.add("A");
        sh.add("a");
        sh.add("C");
        sh.add("c");
        sh.add("a");
        for(String s1:sh)
        {
            System.out.println(s1);
        }
        System.out.println("HashSet不能成功添加");
        
        Set<String> st=new TreeSet<String>();
        st.add("A");
        st.add("a");
        st.add("C");
        st.add("c");
        st.add("a");
        for(String s2:st)
        {
            System.out.println(s2);
        }
        System.out.println("TreeSet不能成功添加");

    }

}
View Code

 

第三题:

package Zuoye1;

import java.util.*;;

public class Emp {

    private String key;
    private String value;
    
    public Emp(String key,String value)
    {
        this.key=key;
        this.value=value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    
    
    
    public static void main(String args[])
    {
        
        Map<String,String> m=new HashMap<String,String>();
        Emp emp=new Emp("001","张大");
        Emp emp1=new Emp("002","李四");
        Emp emp2=new Emp("003","王五");
        Emp emp3=new Emp("004","冯一");
        Emp emp4=new Emp("005","钱六");
        Emp emp5=new Emp("006","马三");
        
        m.put(emp.getKey(), emp.getValue());
        m.put(emp1.getKey(), emp1.getValue());
        m.put(emp2.getKey(), emp2.getValue());
        m.put(emp3.getKey(), emp3.getValue());
        m.put(emp4.getKey(), emp4.getValue());
        m.put(emp5.getKey(), emp5.getValue());
        
        for(String t:m.keySet())
        {
            if(t=="005")
            {
                m.remove(emp4);
            }
            else
            {
                System.out.println(t);
            }
        }
        
    }
    
}
View Code

posted @ 2016-03-11 21:34  百事没事  阅读(172)  评论(0编辑  收藏  举报