首页 > 其他 > 详细

第二题,第三题

时间:2016-03-11 22:25:29      阅读:286      评论:0      收藏:0      [点我收藏+]

第二题:

技术分享
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

技术分享

第二题,第三题

原文:http://www.cnblogs.com/1ming/p/5267320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!