Hello, I'm currently working on a small database project with various search algorithms. Right now I seem to be a little stumped. Basically what I need to is to read a huge file of strings, such as these 2 lines:
Abram,Smith,70,M,Nursing Unit,324b
Ace,Lewis,7,M,Intensive Care Unit,324c
I then need to delimit these into an array. From this I need to create a 2D array, so after the delimit(on comma) I would have an array that looks like this:
[Abram, Smith, 70, M, Nursing Unit, 324b]
And the end game being an array of arrays of each line so I can access each dept etc by merely using array[x][4]
[[Abram, Smith, 70, M, Nursing Unit, 324b],[Ace,Lewis,7,M,Intensive Care Unit,324c]]
I then need to add this to the 2D array and then use a bubble sort to sort by department (Nursing Unit, Intensive Care, etc). The above list is always separated by a carriage return with commas in between first name, last name, and so on, and the indexes for the subjects are the same. i.e. Department is always at index 4. I'm having trouble taking all of the delimited single arrays after reading the file and adding them as they are read into a 2D array, heres my code:
){
File medicalfile= new File("medical_database.txt");
String getinput;
String delimiter[];
int count=0;
int x=0, y=0;
Scanner scan=null;
patients=new String[999][6];
try
{
scan=new Scanner(medicalfile);
}
catch(Exception e){}
while(scan.hasNext())
{
getinput=scan.nextLine();
delimiter=getinput.split(",");
System.out.println(Arrays.toString(delimiter));
for(int i=0;i<999;i++)
{
for(int j=0;j<delimiter.length;j++)
{
patients[i][j]=delimiter[j];
}
}
}
}
Now I know that the last for loop will leave me with the last entry scanned covering the entire 2D array, but I've just exhausted a lot of options, any suggestions? I've done so much debugging so I know almost how everything prints out but the reading once per line is really confusing me