Tuesday, 17 September 2013

How to make an array list of objects in Java

How to make an array list of objects in Java

Having this:
static class girl{
public String age;
public String name;
public String id;
}
static girl[] girl;
Then i am unable to do this in my main function:
ResultSet r = s.executeQuery("select count(*) from children");
r.next();
girl_count=r.getInt(1);
girl = new girl[girl_count];
r = s.executeQuery("select * from children");
while(r.next()){
int i = r.getString("id");
ifgirl[i]==null)girl[i]=new girl();
girl[i].age=r.getString("age");
girl[i].name=r.getString("name");
girl[i].id=r.getString("id");
}
The above code is not working, what i would like to acheive is:
System.out.println(girl[3]);
especially this line:
girl = new girl[girl_count];
Can anyone help me correct this code ? - or find out what i'm missing here?

No comments:

Post a Comment