Thank you that is so helpful; but i still have a problem in importing unknown number of rows from a CSV file.
plz check the following:
public class array {
public static void main(String[] args) {
// String[] records==new ArrayList<>();
String fileName= "example.csv";
File file= new File(fileName);
try{
Scanner inputStream= new Scanner(file);
while(inputStream.hasNext()){
String data= inputStream.next();
String[] records = data.split(",");
System.out.print(records[2]+ ",");
}
inputStream.close();
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(-1);
}
for (int i = 0; i < records.length - 1; i++) { // error: records cannot be resolved to a variable
int[] r1 = toIntArray(records[i]); // error: records cannot be resolved to a variable
inner:
for (int k = i + 1; k < records.length; k++) { // error: records cannot be resolved to a variable
int[] r2 = toIntArray(records[k]); // error: records cannot be resolved to a variable
if (r1.length == r2.length) {
for (int r = 0; r < r1.length; r++) {
if (r1[r] != r2[r]) {
continue inner;
}
}
System.out.println("row " + i + " equals to row " + k);
}
}
}
}
public static int[] toIntArray(String s) {
String[] tokens = s.split(",");
int[] temp = new int[tokens.length];
try {
for (int i = 0; i < tokens.length; i++) {
temp[i] = Integer.parseInt(tokens[i]);
}
}
catch (Exception e) {
System.out.println(e.getMessage());
System.exit(-1);
}
return temp;
}
}
I dont know how to call rows from the csv file after i saved the data into an array.
Regards