0

I have a text file with content like this:

0   file:/home/lenovo/abc/xyz/2428741   1   0.2406223358908781  3   0.15934924694515487 0   0.1308610400682012  7   0.11295822676896845 9   0.08688547882921284 8   0.08077578857630009 4   0.0784313725490196  6   0.06045751633986928 5   0.029269678886047173    2   0.020389315146348393    
1   file:/home/lenovo/abc/xyz/28397802  1   0.3631535947712418  7   0.1323529411764706  0   0.0988562091503268  8   0.08905228758169935 3   0.07026143790849673 4   0.06004901960784314 9   0.05800653594771242 5   0.049836601307189546    6   0.04861111111111111 2   0.0298202614379085

Where 2428741 is sm usrid,integer 1,2 are topics and double values are probabilities. I want to store these in 2-d matrix p[user][topic]= probability. How can this be done in java?

I have tried by storing different values in arraylists but how do I store them in a matrix?

Mureinik
  • 252,575
  • 45
  • 248
  • 283
  • 1
    Convert to String, [open file, write in file, close file](http://stackoverflow.com/questions/2885173/java-how-to-create-and-write-to-a-file). Also think if you really need a text file for this. A text file is only really needed if a human will modify it. Otherwise check serialization for a binary format, which is faster to save and load. – m0skit0 Mar 27 '14 at 19:21
  • By "Matrix" do you mean "Array"? – Jake Chasan Mar 27 '14 at 19:44
  • You can make an array of arrays, you know. (Though I'd suggest you define a custom class for your user, place the ID, et all in it, and hang an array off it for your "topic" values or whatever. Draw it out on paper so it makes sense.) – Hot Licks Mar 27 '14 at 19:57
  • yes by matrix i mean array – user3104437 Mar 28 '14 at 12:50

0 Answers0