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 郭興華 閱讀(146) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 上饶县| 康保县| 星子县| 铜山县| 尚志市| 商水县| 孙吴县| 霞浦县| 息烽县| 澎湖县| 红桥区| 托克逊县| 大丰市| 京山县| 彭山县| 镇原县| 佛学| 汉源县| 临高县| 鄯善县| 清徐县| 闸北区| 延川县| 武宣县| 台州市| 环江| 南阳市| 肥西县| 金川县| 上饶县| 昌江| 大田县| 炉霍县| 晋州市| 菏泽市| 凌云县| 博乐市| 山丹县| 长兴县| 虎林市| 西华县|