I am writing a program that has to read information from file and put them into ArrayList, I think my code is right but Eclipse is saying :The method add(int, String[]) in the type ArrayList<String[]> is not applicable for the arguments (int, String) about account.add(0, x[0]); in my code.
My code:
public static void main(String args[]) {
ArrayList<String[]> account = new ArrayList<>();
String line = "";
try {
FileReader fr=new FileReader("information.txt");
Scanner information = new Scanner(fr);
while (information.hasNext()) {
// find next line
line = information.next();
String x[]=line.split("-");
account.add(0, x[0]);
account.add(0, x[1]);
account.add(0, x[2]);
}
}
}
tryblock without acatch(or afinallyblock or a resource initialisation).