zoukankan      html  css  js  c++  java
  • 课本235页2-3题

    package org.hanqi.array;
    
    import java.util.*;
    
    public class Xiti2 {
    
        public static void main(String[] args) {
            List<String> list=new ArrayList<String>();
            list.add("A");
            list.add("a");
            list.add("c");
            list.add("C");
            list.add("a");
            for(String s:list)
            {
                System.out.println(s);
            }
            System.out.println("集合长度="+list.size());
            System.out.println("List集合成功添加");
            
            
            HashSet<String>s1=new HashSet<String>();
            s1.add("A");
            s1.add("a");
            s1.add("c");
            s1.add("C");
            s1.add("a");
            for(String t:s1)
            {
                System.out.println(t);
            }
            System.out.println("集合长度="+s1.size());
            System.out.println("Set集合不能成功添加");
    
        }
    
    }

    第三题

    package org.hanqi.array;
    
    import java.util.HashMap;
    import java.util.Map;
    
    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 emp2=new Emp("002","北京烤鸭");
            Emp emp3=new Emp("003","绝味鸭头");
            Emp emp4=new Emp("004","博山酥锅");
            Emp emp5=new Emp("005","武汉热干面");
            Emp emp6=new Emp("006","周村烧饼");
            Emp emp7=new Emp("007","淄博烧烤");
            
            
            m.put(emp.getKey(), emp.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());
            m.put(emp6.getKey(), emp6.getValue());
            m.put(emp7.getKey(), emp7.getValue());
            
            m.remove(emp5);
            for(String t:m.keySet())
            {
                if(t=="005")
                {
                    m.remove(emp5);
                }
                else
                {
                    System.out.println(t);
                }
            }
        }
    
    }

  • 相关阅读:
    uva 11294 Wedding
    uvalive 4452 The Ministers’ Major Mess
    uvalive 3211 Now Or Later
    uvalive 3713 Astronauts
    uvalive 4288 Cat Vs. Dog
    uvalive 3276 The Great Wall Game
    uva 1411 Ants
    uva 11383 Golden Tiger Claw
    uva 11419 SAM I AM
    uvalive 3415 Guardian Of Decency
  • 原文地址:https://www.cnblogs.com/cycanfly/p/5267645.html
Copyright © 2011-2022 走看看