java技術博客

          jsp博客
          數據加載中……
          ArrayListTest.java
          /**
          *i測試數組列表的使用
          */
          import java.util.ArrayList;
          public class ArrayList{
          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 strAddress="";
          public Student(String name,String number){
          strName=name;
          strNumber=number;
          }
          public String getStudentName(){
          return strName;
          }
          public String getStudentNumber() {
          return strNumber;
          }
          public String 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 setStudentSpececiality(String speciality){
          strSpeciality=speciality;
          }
          public void setStudentAddress(String address){
          strAddress=address;
          }
          public String toString(){
          String information="student name="+strName+",student number="+strNumber;
          if(!strSex.equals(""))
          information+=",sex="+strSex;
          if(!strBirthday.equals(""))
          information+=",birthday="+strBirthday;
          if(!strSpeciality.equals(""))
          information+=",專業="+strSpeciality;
          if(!strAddress.equals(""))
          information+=",籍貫="+strAddress;
          return information;
          }
          }

          posted on 2008-10-22 23:33 郭興華 閱讀(141) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 米泉市| 南城县| 得荣县| 舒城县| 钟祥市| 白水县| 奉节县| 镇平县| 都匀市| 鹿泉市| 青铜峡市| 金秀| 阳信县| 海南省| 新蔡县| 韶山市| 龙陵县| 榆中县| 贵州省| 泸水县| 梁河县| 临桂县| 荥阳市| 新余市| 安徽省| 黄大仙区| 凤山市| 通山县| 晋江市| 清水县| 柘城县| 兴仁县| 远安县| 孝义市| 咸宁市| 白河县| 河北区| 高阳县| 德清县| 永兴县| 新干县|