0
public static void main(String[] args) throws IOException
{
   String fileloc = "src\\assignment12\\Areas.csv";
   List<data> list = new ArrayList<data>();
    try {
       BufferedReader br = new BufferedReader(new FileReader(fileloc));
       String line = null;
       String read = br.readLine();
       while (read != null){

        String temp[] = read.split(",");  

        list.add(new data(temp[0], temp[1], temp[2], temp[3], temp[4]));

     System.out.println(list);
       }


       br.close();
   }catch (IOException e){
       System.out.println("Error Reading FIle");
   }
}

my data class

public class data extends States{
private String state;
private String total;
private String land;
private String water;
private String waterperc;

public data(String state, String total, String land, String water, String waterperc){



    this.state = state;
    this.total = total;
    this.land = land;
    this.water = water;
    this.waterperc = waterperc;
}

public String state(){
    return state;
}

public void getState(String state){
    this.state = state;
}

public String total(){
    return total;
}

public void getTotal(String total){
    this.total = total;
   }

public String land(){
    return land;
}

public void getLand(String land){
    this.land = land;
}
public String water(){
    return water;
}

public void getWater(String water){
    this.water = water;
}
public String waterperc(){
    return waterperc;
}

public void getWaterperc(String waterperc){
    this.waterperc = waterperc;
}
}

I'm pretty new at coding so please be nice haha!

When i try to convert the array from the second to the last, it won't let me convert the data from my String to double.

Am I missing something or am I just completely just not understanding?

kiner_shah
  • 3,939
  • 7
  • 23
  • 37
Adriel Z
  • 1
  • 1
  • *when i try to convert the array from the second to the last*: what does that mean? What exact and complete error do you get? Hint: how many times do you call readLine()? – JB Nizet Apr 30 '17 at 15:54
  • Possible duplicate of [JAVA - import CSV to ArrayList](http://stackoverflow.com/questions/7712524/java-import-csv-to-arraylist) – Adam Apr 30 '17 at 15:54
  • I guess it should be `while((read = br.readLine()) != null)`! And what's the use of variable `line`? – kiner_shah Apr 30 '17 at 16:01
  • 1
    Maybe you need to use type Object // ArrayList list = new ArrayList(); // for your list. It's more common approach – Vasyl Lyashkevych Apr 30 '17 at 16:20
  • well the csv file is like this North Carolina,140,130,13,10 Indiana,94,93,1.5,1.6 Wyoming,250,250,1.9,0.70 – Adriel Z May 01 '17 at 01:17

0 Answers0