Possible to dynamically create strings?
I have recently got back in to Java after a number of years so I am slowly getting back up to speed again. I was wondering if anybody can help or point me in the right direction with the following:
I have written a UI which depending on the options chosen generates a properties file which I am then using in a method.
Certain parts of the properties file are always the same and I have successfully written code to read from the file, parse the information and add it to a string.
My problem is that depending on the options from the UI there can be X number of lines that I want to read into strings, for example part of the properties file looks like this:
xA1=Answer To XQ1
xA2=Answer To XQ2
xA3=Answer To XQ3
What I am stuck with is a way in my java method to dynamically create strings to hold this information.
Can anyone suggest a way to do this or recommend something else to archive this?
Re: Possible to dynamically create strings?
That sounds like you need to use a collection like an ArrayList to contain the Strings. It can hold X number of items.
there can be X number of lines that I want to read into strings
Not sure what you mean by "dynamically create strings". You seem to be asking how to create new variable names when a program executes. Variable names are created when a file is editted. Using a collection will give you a "new name" for a variable that includes the collection name plus the value of the index into the collection: collection.get(0) is the "name" for the first item in the collection,
method to dynamically create strings to hold this information.
collection.get(1) is the name for the second item, etc
Instead of having parallel collections, create an object that contains the question and its answer and put those new objects into the collection.