File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Alternatives to arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

Alternatives to arrays

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191

I have a program which needs to store data from text files (comprising of several Mb). I am storing this data into a number of arrays.

To do so, I am currently reading these files once to get the number of lines so that I can get the array length that will be required.

I am then reading the file again and storing this data as the file reader read line by line.

Is there is anything else other than arrays I can use which would mean I dont have to read the file twice? In addition, creating these large arrays are giving me the OutOfMemory heap problem.


Moosey knows best
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11952

well, if you're storing the whole thing in memory, i'm not sure changing the storage object will help much with the outofmemory error.

do you need to store the whole thing in memory? I would think that what you are doing with the data should determine what you use to store it...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Well basically Im ending up with a 2d array with dimensions over 20000 by 20000. The idea this is then put into a text file as a grid
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Okay, let's not waste people's time by having the same conversation twice. The other thread seems to have more info, so I'll close this one. Followups can go here please.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Alternatives to arrays
It's not a secret anymore!