I want to be able to loop through the second column of a csv file and find the indexes of a particular string. So for example find all the indexes with the value "Chelsea". Below is the code I have so far.
Any Help?
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class CSVReader {
public static void main(String[] args) {
CSVReader obj = new CSVReader();
obj.run();
}
public void run() {
String csv = "2015:2016.csv";
BufferedReader br = null;
String line = "";
String csvSplit = ",";
String[] football = new String[0];
try {
br = new BufferedReader(new FileReader(csv));
String headerLine = br.readLine();
while ((line = br.readLine()) != null) {
football = line.split(csvSplit);
}
}
catch (IOException io) {
System.out.println(io);
}
}
}
football[1]will give you second column. Also, you will probably need a loop or an even better approach (like reading all the lines at once using theFiles.readAllLines()Files.readAllLines()will load all your file into memory so make sure that the file will never be big before using this appraoch