Converting a text file to an array in Java -


i'm beginner @ java , have list of 25 students include name, age, income , iq in text file. i'm struggling how take text file , put in array can sort them , such. far have:

file myfile = new file ("./src/project2/studentlist"); scanner myscan = new scanner(myfile);  while (myscan.hasnext()) {      string line = myscan.nextline();     scanner scanner = new scanner(line);     scanner.usedelimiter(",");      while (scanner.hasnext()) {         string name = scanner.next();         string age = scanner.next();         string income = scanner.next();         string smart = scanner.next();          student students = new student(name, age, income, smart);           system.out.println(students);     } } 

i want know easiest way go this. i'm close, can feel it! in advance.

define array:

student[] students = new student[25]; int = 0; 

then in loop

student student = new student(name, age, income, smart); students[i++] = student; 

or dynamic array

list<student> students = new arraylist()<>; 

and in loop:

student student = new student(name, age, income, smart); students.add(student); 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -