Filling in uninitialized array in java? (or workaround!)

Posted by AlexRamallo on Stack Overflow See other posts from Stack Overflow or by AlexRamallo
Published on 2010-12-29T01:47:09Z Indexed on 2010/12/29 1:54 UTC
Read the original article Hit count: 132

Hello all,

I'm currently in the process of creating an OBJ importer for an opengles android game. I'm relatively new to the language java, so I'm not exactly clear on a few things.

I have an array which will hold the number of vertices in the model(along with a few other arrays as well):

float vertices[];

The problem is that I don't know how many vertices there are in the model before I read the file using the inputstream given to me.

Would I be able to fill it in as I need to like this?:

vertices[95] = 5.004f; //vertices was defined like the example above

or do I have to initialize it beforehand?

if the latter is the case then what would be a good way to find out the number of vertices in the file? Once I read it using inputstreamreader.read() it goes to the next line until it reads the whole file. The only thing I can think of would be to read the whole file, count the number of vertices, then read it AGAIN the fill in the newly initialized array.

Is there a way to dynamically allocate the data as is needed?

© Stack Overflow or respective owner

Related posts about java

Related posts about android