Results 1 to 3 of 3
- 12-09-2012, 01:07 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
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:
xQ1=Question1
xA1=Answer To XQ1
xQ2=Question2
xA2=Answer To XQ2
xQ3=Question3
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?
- 12-10-2012, 01:04 AM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Possible to dynamically create strings?
I am not sure if I get your problem... of course you can do all things with strings you like:
String myString = reader.readLine();
String otherString = myString + ":" + newText;
...
what exactly is the problem? Maybe you should post what you have (include your code into CODE brackets on this forum when you post it)
Maybe your problem is to actually "store" the strings? Then you should give the "ArrayList<String>" a try... ;)Last edited by Sierra; 12-10-2012 at 09:44 AM. Reason: fixed syntax errors
I like likes!.gif)
- 12-10-2012, 05:59 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: Possible to dynamically create strings?
In Java you can create strings dynamically - write a for loop and include statements using the "new" statement. (In fact everything that can possibly happen in a program happens dynamically. When a program ceases to be dynamic users assume the d@mn thing has crashed)
What you can't do is create variables at runtime. And there's no real heed to. As the previos post says, use a list or an array to store your strings.
Similar Threads
-
how to create row dynamically into jtable on netbeans
By suhailt in forum NetBeansReplies: 1Last Post: 10-02-2011, 09:41 PM -
Dynamically create objects, set value and call
By buntyindia in forum New To JavaReplies: 5Last Post: 05-25-2011, 05:59 PM -
Dynamically create a button, but what happened?
By love2java in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 12:01 AM -
How to create widgets dynamically
By sarbuland in forum Advanced JavaReplies: 0Last Post: 02-06-2008, 08:08 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks