Commit 9671cc23 authored by edmundszagars's avatar edmundszagars
Browse files

Fixing "getDataFromCSV" to return correct data type

parent 0f528cdd
1, 2, 3
1, 2, 3, 4
\ No newline at end of file
......@@ -8,21 +8,21 @@ import java.util.Scanner;
public class GetDataFromCSV {
private String nFileLocation = "data.csv";
public ArrayList getDataFromCSV() throws FileNotFoundException {
public List<ArrayList<Double>> getDataFromCSV() throws FileNotFoundException {
List<ArrayList<Double>> nListOfValues = new ArrayList<>();
Scanner scanner = new Scanner(new BufferedReader(new FileReader(nFileLocation)));
while (scanner.hasNextLine()){
while (scanner.hasNextLine()) {
String nLine = scanner.nextLine();
String[] inArray = nLine.split(",");
ArrayList<Double> list = new ArrayList<>();
for (String anInArray : inArray) {
list.add(Double.parseDouble(anInArray));
}
if(list.size() != 0){
if (list.size() != 0) {
nListOfValues.add(list);
}
}
return (ArrayList) nListOfValues;
return nListOfValues;
}
public void setnFileLocation(String nFileLocation) {
......
......@@ -4,7 +4,8 @@ import java.util.Arrays;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
GetDataFromCSV get = new GetDataFromCSV();
get.setnFileLocation("data2.csv");
for (int i = 0 ; i < get.getDataFromCSV().size();i++)
System.out.println(get.getDataFromCSV().get(i));
System.out.println(get.getDataFromCSV().get(i).size());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment