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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 沿河| 大英县| 米易县| 阜阳市| 乡宁县| 朔州市| 上饶市| 鄂托克旗| 若羌县| 仙游县| 长宁县| 梓潼县| 乳源| 蛟河市| 古丈县| 绥芬河市| 冷水江市| 南投市| 泽库县| 同仁县| 察雅县| 赞皇县| 沿河| 教育| 望谟县| 桂阳县| 济宁市| 明水县| 平湖市| 漾濞| 易门县| 沙洋县| 逊克县| 自贡市| 滨海县| 兰州市| 莲花县| 昌都县| 丰宁| 和龙市| 县级市|