I was trying to find the largest value in a specific column but so far my code only prints that column on the console. How can I read through the last column only and find the largest value and print that entire row where the largest number is found?
BufferedReader csvReader = null;
try {
csvReader = new BufferedReader(new FileReader(selectedFile.getAbsolutePath()+"\\FinalResults.csv"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String line = null;
try {
while ((line = csvReader.readLine()) != null) {
String[] cols = line.split(",");
System.out.println("Coulmn 3= " + cols[2]);
}
} catch (IOException e) {
e.printStackTrace();
}
Updated Code
int largestSoFar = Integer.MIN_VALUE ;
BufferedReader csvReader = null;
try {
csvReader = new BufferedReader(new FileReader(selectedFile.getAbsolutePath()+"\\FinalResults.csv"));
System.out.println(selectedFile.getAbsolutePath()+"\\FinalResults.csv");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String line = null;
try {
while ((line = csvReader.readLine()) != null) {
String[] cols = line.split(",");
int number = Integer.parseInt( cols[2] ) ;
if ( number > largestSoFar ) { largestSoFar = number ; }
// calculateMinAndMax(cols[2]);
System.out.println(number);
// System.out.println("Coulmn 3= " + cols[2]);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}