java技術博客

          jsp博客
          數據加載中……
          Arraylist

           

          /**
           * 測試數組列表的使用
           
          */

           
          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 = "";//學生姓名
              private String strNumber = "";//學號
              private String strSex = "";//性別
              private String strBirthday = "";//出生年月
              private String strSpeciality = "";//專業
              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 
          = "學生姓名=" + strName + ", 學號=" + strNumber;  
                  
          if!strSex.equals("") )
                      information 
          += ", 性別=" + strSex;
                  
          if!strBirthday.equals(""))
                      information 
          += ", 出生年月=" + strBirthday;
                  
          if!strSpeciality.equals("") )
                      information 
          += ", 專業=" + strSpeciality;
                  
          if!strAddress.equals("") )
                      information 
          += ", 籍貫=" + strAddress;
                  
          return information;
              }

          }

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


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 惠州市| 错那县| 河北省| 周宁县| 余姚市| 大同市| 中江县| 秦安县| 定远县| 镇平县| 高州市| 西畴县| 嵩明县| 安龙县| 神农架林区| 泌阳县| 泗洪县| 鄂托克旗| 太仆寺旗| 应用必备| 红桥区| 馆陶县| 奇台县| 沙坪坝区| 沈丘县| 紫云| 榕江县| 来安县| 弥渡县| 平山县| 齐齐哈尔市| 方正县| 菏泽市| 宁陕县| 金门县| 永泰县| 奉新县| 和龙市| 利川市| 平昌县| 宁远县|