Using getters and setters with ArrayLists in java
<p>I'm trying to read a csv and storing the records in an ArrayList.
Since I know the no. of records in the csv file I'm specifying the size i.e. 600 when creating the object.
I want the program to be able to read files of unknown no. of records.
How do I make it dynamic.</p>

<p>Here's the working code for the file with 600 records.</p>

<pre><code>import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.*;


public class BankRecords extends Client{
//Create objects for processing data
//private static int count;
static BankRecords[] obj=new BankRecords[600];
static List&lt;List&lt;String&gt;&gt; array = new ArrayList&lt;List&lt;String&gt;&gt;();
@Override
void readData() {
    // TODO Auto-generated method stub
    String line=" ";
    //int i=0;

    //try with resources statement
    try(BufferedReader br = new BufferedReader(new FileReader("bank-Detail.csv"))){

        while((line=br.readLine()) != null) //read from file
        {   
            array.add(Arrays.asList(line.split(",")));
            //check data
            //count++;
            //System.out.println(array.get(i++));
        }

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    processData();
}
@Override
void processData() {
    // TODO Auto-generated method stub

    int idx=0;
    for(List&lt;String&gt; bankData: array)
    {

        obj[idx]= new BankRecords();
        obj[idx].setId(bankData.get(0));
        obj[idx].setAge(Integer.parseInt(bankData.get(1)));
        obj[idx].setSex(bankData.get(2));
        obj[idx].setRegion(bankData.get(3));
        obj[idx].setIncome(Double.parseDouble(bankData.get(4)));
        obj[idx].setMarried(bankData.get(5));
        obj[idx].setChild(Integer.parseInt(bankData.get(6)));
        obj[idx].setCar(bankData.get(7));
        obj[idx].setSact(bankData.get(8));
        obj[idx].setCact(bankData.get(9));
        obj[idx].setMort(bankData.get(10));
        obj[idx].setPep(bankData.get(11));


        idx++;

        //System.out.println(obj[idx].getId());
        }

    printData();
}





@Override
void printData() {

    //Printing First 25 ID, age, sex, region, income and mortgage
    System.out.println("ID\t\tAGE\t\tSEX\t\tREGION\t\tINCOME\t\tMORTGAGE\n");
    for(int i=0;i&lt;25;i++){

        String s=String.format("%s\t\t%s\t\t%s\t\t%-10s\t%8.2f\t%2s", obj[i].getId(),obj[i].getAge(),obj[i].getSex(),obj[i].getRegion(),obj[i].getIncome(),obj[i].getMort());
        System.out.println(s);
    }
}
public String getId() {
    return id;
}




public void setId(String id) {
    this.id = id;
}




public int getAge() {
    return age;
}




public void setAge(int age) {
    this.age = age;
}




public String getSex() {
    return sex;
}




public void setSex(String sex) {
    this.sex = sex;
}




public String getRegion() {
    return region;
}




public void setRegion(String region) {
    this.region = region;
}




public double getIncome() {
    return income;
}




public void setIncome(double income) {
    this.income = income;
}




public String isMarried() {
    return married;
}




public void setMarried(String married) {
    this.married = married;
}




public int getChild() {
    return child;
}




public void setChild(int child) {
    this.child = child;
}




public String getCar() {
    return car;
}




public void setCar(String car) {
    this.car = car;
}




public String getSact() {
    return sact;
}




public void setSact(String sact) {
    this.sact = sact;
}




public String getCact() {
    return cact;
}




public void setCact(String cact) {
    this.cact = cact;
}




public String getMort() {
    return mort;
}




public void setMort(String mort) {
    this.mort = mort;
}




public String getPep() {
    return pep;
}




public void setPep(String pep) {
    this.pep = pep;
}




public static void main(String[] args) {
    // TODO Auto-generated method stub
    BankRecords bnk= new BankRecords();
    bnk.readData();
}
</code></pre>

<p>}</p>