PDA

View Full Version : Another Java question


LoD
01-06-2004, 19:29:15
OK, so I've got this problem. I have to read a string containing a definition of several objects. The problem - it is not specified how many, so I only know the number of those after I read the entire string. So here is a question - is there a possibility to dynamically name variables like in PHP? The two solutions I've found so far, namely:
-create a new array everytime a new object is read,
-read the entire string, then split it up somehow (through tokenizing or other ways),
strike as a bit ineffective.

Any help is extremely welcome :).

Asher
01-06-2004, 20:19:05
Er, what's the problem? (not clear to me)

Use Vectors?

Asher
01-06-2004, 20:20:23
It sounds like you're doing some kind of parser, in which case the easiest way is to read it in and then tokenize...

LoD
01-06-2004, 20:54:10
Well, actually the parser is only a part of the problem. The task is (for your interest) to read a definition of a computer network (list of computers each with an address book and a "vulnerability flag") and simulate the spread of an email worm through said network. Now the spread algorithm (supposedly the hardest) is trivial for me, it's the storage of objects that's causing me problems :)...


Originally posted by Asher
Use Vectors?

That seems to do the trick, thanks :)!