Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:48:01+00:00 2026-05-26T09:48:01+00:00

Basically I have a variable, zlort = one; I want to concatenate the value

  • 0

Basically I have a variable, zlort = one;

I want to concatenate the value of zlort into a variable (object reference) name.

Like

BankAccount Accountzlort = new BankAccount;

I want the zlort in Account.zlort to actually be the replaced with value of zlort (one–meaning I want the value to be Accountone), and not zlort itself.

Is it possible to do this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:48:01+00:00Added an answer on May 26, 2026 at 9:48 am

    After reading the explanations in your comments, the fact that you can’t use an array but can use an `ArrayList’…

    Rather than creating a new variable name (or array element, or map value) for each BankAccount, you can probably use scope to your advantage.

    Scope is the concept that a reference to a variable only has meaning within a certain part of code. If you declare a variable inside a method, that variable can only be seen within that method. A variable declared within a block (a loop, if statement, etc ) can only be seen from within that block.

    Class fields have a different kind of scoping that can be adjusted with keywords (see here).

    For example:

    public class ScopeExample
    
        int classInt = 10;
    
        public void method() {
            int methodInt = 0; // This integer can only be seen by code in 
                               // this method
        }
    
        public void method2() {
            //doSomething(methodInt) // This line won't compile because i is 
                                     // declared in a different method!
            doSomething(classInt); // This line will compile and work 
                                   // because x is declared in the class that 
                                   // contains this method.
            int index = 0;
            while (index < 3) {
                int whileInt = index; // This integer can only be seen from within 
                                      // this while loop! It is created each 
                                      // loop iteration.
                doSomething(whileInt);
            }
            doSomething(whileInt); //This line won't work, whileInt is out of scope!
        }
    
        public doSomething(int a) {
            System.out.println(a);
        }
    
    }
    

    SO! If you create a BankAccount object within the loop, you don’t have to worry about creating a new name for the next one. Each time the loop iterates it will become a new object (when you create it).

    If you have to store it, you definitely will need to use an array or other data structure (ArrayList!).

    Building on the idea of scope, you -can- have the same variable name for each new BankAccount. A variable reference name isn’t guaranteed to be paired with the object that it refers to. That is a convenience to the programmer, so you don’t have to know the exact memory address it is being stored in.

    For example:

    public static void main(String[] args) {
    
        Object o;
        int i = 0;
        while (i < 5) {
            Object reference = new Object(); // Create a new Object and store 
                                             // it in 'reference'
            o = obj; // The Object 'o' now refers to the object in 'reference'
            i++;
        }
        System.out.println(o); // This should print information about the 
                               // LAST object created.
    }
    

    The new Object created in the loop does not belong to ‘obj’. You as a programmer use ‘obj’ to point to the Object. The program doesn’t really know what obj means, other than the fact that it points to the Object you just created.

    Finally, you can use this along with an ArrayList to make your life easier.

    public static void main(String[] args) {
    
        // Our new ArrayList to hold our objects!
        ArrayList<Object> stuff = new ArrayList<Object>();
    
        int i = 0;
        while (i < 5) {
            Object obj = new Object(); // Create an object and make obj point to it.
            stuff.add(obj); // Put "the object that 'obj' points to" in 'stuff'.
            i++;
        }
    
        // This loop goes through all of the Objects in the ArrayList and prints them
        for (int index = 0; index < stuff.size(); index++) {
            System.out.println(stuff.get(i)); // This will print a single 
                                              // object in the ArrayList each time.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically i have a variable that holds a time value, in this format '00:04:13.67'.
Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
I have a String variable (basically an English sentence with an unspecified number of
Basically I have some variables that I don't want to preinitialize: originalTime = None
Basically, I want to have my program retrieve various variables from the hard drive
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
Basically I have a User-Defined Table Type (for use as a table-valued variable) which
Basically i have a query string that when i hardcode in the catalogue value
Basically this everything I have been trying to have session variable on same page
I have a variable $Date that is automatically updated each day. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.