need help for arraylist for storing the data
i need to store a DatSet value into ArrayLis开发者_运维问答t
while(result.next())
{
String Adress= result.getString(1);
String Name = result.getstring(2);
}
now the loop executes and i want to store the value of loop in the array list so can anybody please help me on this i am new to arraylist.
Here's a simple example:
class Person
{
String address;
String name;
public Person(String name, String address)
{
this.name = name;
this.address = address;
}
}
...
List<Person> persons = new ArrayList<Person>();
while(result.next())
{
String Adress= result.getString(1);
String Name = result.getstring(2);
persons.add(new Person(Name, Address));
}
You must create a class to hold the row data, then add the objects of that class to an ArrayList.s
精彩评论