java技術博客

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

           

          /**
           * 測試數(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 = "";//學生姓名
              private String strNumber = "";//學號
              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 
          = "學生姓名=" + strName + ", 學號=" + 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 郭興華 閱讀(223) 評論(0)  編輯  收藏


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 平阳县| 聊城市| 仁怀市| 克什克腾旗| 工布江达县| 松潘县| 健康| 南平市| 台北县| 舟山市| 顺昌县| 敦化市| 电白县| 崇州市| 商南县| 宜阳县| 福安市| 九江市| 卓资县| 肃北| 葫芦岛市| 九龙坡区| 雷州市| 平安县| 隆回县| 新宁县| 家居| 浏阳市| 合水县| 松溪县| 称多县| 尤溪县| 芒康县| 射洪县| 通州市| 镇原县| 蒲城县| 玉环县| 利津县| 垦利县| 庆安县|