• 第九次作业


    把多个企鹅的信息添加到集合中
    查看企鹅的数量及所有企鹅的信息
    删除集合中部分企鹅的元素
    判断集合中是否包含指定企鹅

    package xz7;
    
    public class chap {
        String name="无名氏";
        String sex="Q仔";
        public chap(String name,String sex){
            this.name=name;
            this.sex=sex;
        }
        public String getName(){
            return name;
        }
        public void setName(String name){
            this.name=name;
        }
        public String getSex(){
            return sex;
        }
        public void setSex(String sex){
            this.sex=sex;
        }
    
    }
    package xz7;
    
    import java.awt.List;
    import java.util.ArrayList;
    
    public class Test {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            //把多个企鹅的信息添加到集合中
            chap ououchap=new chap("欧欧","Q仔");
            chap yayachap=new chap("亚亚","Q妹");
            chap meimeichap=new chap("美美","Q妹");
            chap feifeichap=new chap("菲菲","Q妹");
            
            ArrayList penList=new ArrayList();
            penList.add(ououchap);
            penList.add(yayachap);
            penList.add(meimeichap);
            penList.add(feifeichap);
            //查看企鹅的数量及所有企鹅的信息
            System.out.println("共计有"+penList.size()+"只企鹅。");
            System.out.println("分别是:");
            for(int i=0;i<penList.size();i++){
                chap qe=(chap)penList.get(i);
                System.out.println(qe.getName()+"	"+qe.getSex());
            }
            //删除集合中部分企鹅的元素
            penList.remove(yayachap);
            penList.remove(feifeichap);
            System.out.println("
    删除之后还有"+penList.size()+"只企鹅。");
            System.out.println("分别是:");
            for(int i=0;i<penList.size();i++){
                chap qe=(chap)penList.get(i);
                System.out.println(qe.getName()+"	"+qe.getSex());
            }
            //判断集合中是否包含指定企鹅
            if(penList.contains(meimeichap))
                System.out.println("
    集合中包含美美的信息");
            else
                System.out.println("
    集合中不包含美美的信息");
        }
    
    }

  • 相关阅读:
    Memcached 缓存服务器介绍
    hibernate ——联合主键
    hibernate ——关联关系
    Spring与Struts整合
    spring-DataSource
    hibernate ——helloWorld程序(annotation配置)
    hibernate ——helloWorld程序(XML配置)
    Struts2 知识体系
    Encoding filter 编码过滤器
    jQuery.ajax() 函数详解
  • 原文地址:https://www.cnblogs.com/3469656421aixz/p/13027431.html
Copyright © 2020-2023  润新知