Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Sierra

Thread: Possible to dynamically create strings?

  1. #1
    ajrobson is offline Member
    Join Date
    Dec 2012
    Rep Power

    Question 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?

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Rep Power

    Default 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
    pbrockway2 likes this.
    I like likes!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default 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

  1. Replies: 1
    Last Post: 10-02-2011, 09:41 PM
  2. Dynamically create objects, set value and call
    By buntyindia in forum New To Java
    Replies: 5
    Last Post: 05-25-2011, 05:59 PM
  3. Dynamically create a button, but what happened?
    By love2java in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 12:01 AM
  4. How to create widgets dynamically
    By sarbuland in forum Advanced Java
    Replies: 0
    Last Post: 02-06-2008, 08:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts