I have wrriten a code to save data from a text file into any array list. I am using array list for the first time. I have used only array before. In the text file I have data that is seperated by comma , I need each element to be stored in a seperate array position that is .....
in the above line number one should be stored in array position 1,1......number 10 should be stored in array position 1,2...like a two dimensional array.....here is my code...
Well, I think you have a couple problems that you've brought up:
1. your treating your list as "line separated values" not comma separated...because you are treating each line as a string data element. If that is truly what you want to do (which is doubtful) and all you want to do is print it out like that, do as Rob suggested and just iterate over the array with a for loop and print each value on a new line.
2. If your numbers are truly independent values, your structure needs to change. You can't make a 2-dimensional array list, so your options are either:
a. capture each value individually, and use modular arithmetic on the ArrayList to index into the correct position or for printing.
b. use nested ArrayLists as in:
You probably want to do something like (b.) above. In that example, you have an array of patients....each patient has an array of "data values". And you're treating your list of numbers as independent values instead of as a String.