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 郭兴华 阅读(210) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: