creating dynamic VARIABLE in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bora Ji
    New Member
    • May 2007
    • 1

    creating dynamic VARIABLE in java

    Please help me to creating dynamic VARIABLE in java, with predefined name.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Bora Ji
    Please help me to creating dynamic VARIABLE in java, with predefined name.
    You can't without substantial byte code fiddling. Better use a Map<String, Object>
    in which you store the associations between names and values.

    kind regards,

    Jos

    Comment

    • mufumbo
      New Member
      • May 2007
      • 3

      #3
      what do you want to do?

      Comment

      • slauper
        New Member
        • May 2009
        • 1

        #4
        create the variable name with a concat with the loop counter variable name to get the

        HOW TO DO THIS ?


        //Variable Declaration
        String col_width_1 = "100px";
        String col_width_2 = "150px";
        //etc String col_width_N = "XXXpx";

        //loop
        for (int h = 0; h < hrecset.getRowC ount(); h++)
        {
        //some code
        //create the variable name with a concat with the loop counter variable name to get the value of the concatened variable
        out.println("<t d style=\"width: "+col_width_+h+ " \">")//Do you understand what i mean?
        //some code
        }
        Last edited by slauper; May 15 '09, 11:47 AM. Reason: It is a question not a solution

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Use an array or read my first reply; btw, don't hijack threads; it is considered rude. Start your own thread instead.

          kind regards,

          Jos

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by slauper
            Code:
            for (int h = 0; h < hrecset.getRowCount(); h++)
            {
             //some code
            }
            Don't use this .. because every time the system executes hrecset.getRowC ount().
            Instead use,

            Code:
            int rowCount = hrecset.getRowCount();
            for (int h = 0; h < hrecset.getRowCount(); h++)
            {
             //some code
            }

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by dmjpro
              ..
              Instead use,

              Code:
              int rowCount = hrecset.getRowCount();
              for (int h = 0; h < hrecset.getRowCount(); h++)
              {
               //some code
              }
              Possibly a typo on your part but you posted the same code that he used.

              Comment

              Working...