數(shù)據(jù)加載中……
          Arraylist

           

          /**
           * 測(cè)試數(shù)組列表的使用
           
          */

           
          import java.util.ArrayList;

          public class ArrayListTest
          {
              
          public static void main(String[] args)
              
          {
                  ArrayList list 
          = new ArrayList();
                  list.add(
          new Student("Tom","20020410"));
                  list.add(
          new Student("Jack","20020411"));
                  list.add(
          new Student("Rose","20020412"));

                  
          for(int i = 0; i < list.size(); i++)
                  
          {
                      System.out.println((Student)list.get(i));
                  }

              }

          }


          class Student
          {
              
          private String strName = "";//學(xué)生姓名
              private String strNumber = "";//學(xué)號(hào)
              private String strSex = "";//性別
              private String strBirthday = "";//出生年月
              private String strSpeciality = "";//專業(yè)
              private String strAddress = "";//地址

              
          public Student(String name, String number)
              
          {
                  strName 
          = name;
                  strNumber 
          = number;
              }


              
          public String getStudentName()
              
          {
                  
          return strName;
              }


              
          public String getStudentNumber()
              
          {
                  
          return strNumber;
              }


              
          public void setStudentSex(String sex)
              
          {
                  strSex 
          = sex;
              }


              
          public String getStudentSex()
              
          {
                  
          return strSex;
              }


              
          public String getStudentBirthday()
                  
          {
                  
          return strBirthday;
              }


              
          public void setStudentBirthday(String birthday)
              
          {
                  strBirthday 
          = birthday;
              }


              
          public String getStudentSpeciality()
              
          {
                  
          return strSpeciality;
              }


              
          public void setStudentSpeciality(String speciality)
              
          {
                  strSpeciality 
          = speciality;
              }


              
          public String getStudentAddress()
              
          {
                  
          return strAddress;
              }


              
          public void setStudentAddress(String address)
              
          {
                  strAddress 
          = address;
              }


              
          public String toString()
              
          {
                  String information 
          = "學(xué)生姓名=" + strName + ", 學(xué)號(hào)=" + strNumber;  
                  
          if!strSex.equals("") )
                      information 
          += ", 性別=" + strSex;
                  
          if!strBirthday.equals(""))
                      information 
          += ", 出生年月=" + strBirthday;
                  
          if!strSpeciality.equals("") )
                      information 
          += ", 專業(yè)=" + strSpeciality;
                  
          if!strAddress.equals("") )
                      information 
          += ", 籍貫=" + strAddress;
                  
          return information;
              }

          }

          posted on 2008-11-07 16:34 郭興華 閱讀(224) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 蛟河市| 松潘县| 德阳市| 青海省| 沅江市| 合阳县| 天气| 双流县| 莱西市| 定兴县| 齐河县| 石景山区| 图木舒克市| 申扎县| 建湖县| 阿合奇县| 增城市| 尼勒克县| 普陀区| 重庆市| 高碑店市| 安福县| 峡江县| 彭山县| 宣武区| 平凉市| 绍兴市| 寿阳县| 通山县| 武冈市| 桓台县| 商都县| 台湾省| 周口市| 文水县| 西峡县| 贵南县| 定远县| 西贡区| 汕头市| 阜平县|