Using contents of a String as the name for a variable

I'm trying to write code that will evaluate the contents of a String variable and then use the contents as the name for an object. For example, my program will create an unknown number of Student objects. I would like to name the Student objects student1, student2,... . In the code below, how do I get the last line of the method to create a new Student called something like "student3" instead of "varName"? Thanks, Julie
int numberOfStudents= 0;
public void createStudent()
   numberOfStudents++;
   String varName = "student" + numberOfStudents;
   Student varName = new Student();
}

The name of the reference variable is irrelevant to the functional aspect of the application. The 'Name' should be a property of the student class. EG
class Student {
private String name;
public String getName() { return name; }
public void setName() { this.name = name; }
public Student() { this(null); }
public Student(String name) { setName(name); }
now your code becomes
public void createStudent() {
numberOfStudents++;
Student newStudent =
new Student("student"+numberOfStudents);
// now do something with the new student...
If you're expecting to use the 'Student' instance outside of this method you need to store a reference to it somewhere more accessible (like a field, in a list or an array) or return the reference from this method...

Similar Messages

  • How do I use CreateBookmarksFromGroupTree and NOT guid in the name for my top level?

    Post Author: Barbdcg
    CA Forum: Deployment
    I have a report that I have created that uses uses groups and I wanted export a PDF using the CreateBookmarksFromGroupTree option. While that works, I get an ugly top level bookmark name that starts with the name of my report, then followed by a GUID;
    Report {49E72CC5-7FFD-44F8-831B-EA8F543F7D82}.rpt
    So, how do I Put in a name of my own choosing as the top-level bookmark or at least get rid of the guid?
    Any help or suggestions would be appricated.
    Thanks,
    Barb

    Post Author: Barbdcg
    CA Forum: Deployment
    Still no answer??? I can not figure this one out!!  HELP!!!

  • I am unable to reach the my content page of mysites from the name link within my site collection

    For some reason I am no longer able to get to the personal mysites page from within our site collection. My name appears at the top right and it has an option for setting which leads to some minimal page but I can no longer use this to get to the actual
    mysites page. Is there a setting I am missing that allows this to happen?

    Hi,
    According to your post, my understanding is that you failed to reach the content page of mysites from the name link within site collection.
    As this issue is always related to the inadequacy configuration about the MySite, you need to make sure that you had configured correctly with your MySite. You can refer to:
    http://technet.microsoft.com/en-us/library/ee624362(v=office.14)
    What’s more, you can also check with the following steps.
    Make sure the Web site for MySites in IIS is started.
    Make sure the App pool is running
    Use ULSVIEWER to check your Sharepoint ULS logs for the issue.
    There are two similar articles for your reference.
    http://blogs.msdn.com/b/jorman/archive/2009/01/19/sharepoint-my-site-link-stops-redirecting-users-to-their-personal-site.aspx
    http://sharepoint.stackexchange.com/questions/59434/sharepoint-my-profile-404-not-found
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • My old itunes id was an email that no longer can be used, therefore, I can not change the password for that account.  Everything that I purchased under that id name will not play.  How can I fix this?

    My old itunes id was an email that no longer can be used, therefore, I can not change the password for that account.  Everything that I purchased under that id name will not play.  How can I fix this?

    I no longer have an email address that was also my Apple ID. Can I still use the email address as my Apple ID?
    Apple recommends you change your Apple ID to your current, working email address. This will not create another Apple ID, it will only change it to your working email address. See Changing the name you use for your Apple ID if you'd like more information.
    Note: @mac.com and @me.com Apple IDs can not be renamed.  If you no longer use the .mac or .me email address be sure to add your valid email address as an additional email address.
    From here  >  http://support.apple.com/kb/HT5622?viewlocale=en_US
    If necessary...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • Using a variables value as the name of another variable

    Hi, i'm new to java and i've been trying to write a little program. I was wondering whether it is possible to use the value of a variable as the name of another variable.
    This is what i have so far: When i run my java program numerous Animal objects are created with names like ani01, ani02, ani03. These objects have functions like getName() etc. When i type in one of these codes into the command line it gets stored in a variable called 'input'. Everything's fine up to here.
    But i need a way to access the correct Animal from my input. instead of doing countless switch statements on the input.
    If i type "ani02" i want it to return the animals name by calling ani02.getName()...
    how do i do this? i'd appreciate any help. thanks.

    If you were doing this based on user input, then you
    wouldn't have to do a lot of typing. Mmm?I'm sorry i don't get your meaning... ? I am doing this based on user input am i not?
    All i want to do is access the correct Animal object depending on the user's input... so if they type in ani01 it would return 'Elephant' (or whatever) using ani01.getName().
    Maybe i'm going about this the wrong way or something?.. I have about 30 animals. they each have a name, continent, quantity. I have an Animal class that has functions like getName(), setName() etc. When the program starts, 30 objects are created
    Animal ani01 = new Animal("Elephant",3000,"India");
    Animal ani02 = new Animal("Panda",200,"China");etc...
    I want to be able to get information about any one of these animals by typing something at the command line...
    so i type in something (i just thought the name of the object would be the best thing to type in) and i get the info about elephants (or whatever) from the relevant object.
    how would you do this?

  • Display the NAME of a variable

    What's the solution to display the name of a variable :
    For example, if I have :
    int iVar = 2;
    I just want to display "iVar" and not the contents.
    Thanks.

    if you need to get the fields names for any class you can use reflection, some like this.
    import java.lang.reflect.*;
       public class field1 {
          private double d;
          public static final int i = 37;
          String s = "testing";
          public static void main(String args[])
             try {
                Class cls = Class.forName("MyClass");
                Field fieldlist[]
                  = cls.getDeclaredFields();
                for (int i
                  = 0; i < fieldlist.length; i++) {
                   Field fld = fieldlist;
    System.out.println("name
    = " + fld.getName());
    System.out.println("decl class = " +
    fld.getDeclaringClass());
    System.out.println("type
    = " + fld.getType());
    int mod = fld.getModifiers();
    System.out.println("modifiers = " +
    Modifier.toString(mod));
    System.out.println("-----");
    catch (Throwable e) {
    System.err.println(e);
    the result is:
    =================
    name = d
    decl class = class field1
    type = double
    modifiers = private
    name = i
    decl class = class field1
    type = int
    modifiers = public static final
    name = s
    decl class = class field1
    type = class java.lang.String
    modifiers =
    good luck

  • How can i notice the name of global variable ?

    When the customizing.fmx calls the standard.fmx, I came accross an error "FRM-41067 Can not find menu Item".
    customizing.fmx --> call --> standard.fmx
    So, I want to assign a global variable to standard.fmx in the customizing.fmx.
    How can i find out the name of global variable ???
    Can I catch the name of global variable??
    For expamle..
    :global.menu_id was not the answer.
    :global.mn_id was not the answer.
    :global.mnid was not the answer.
    HOW!!!!!!!!!!!!!!!!!!!!
    Please HELP ME!!!

    Hi
    Can I catch the name of global variable?? yes u can , if u use a message after each type like...
    :global.menu_id
    MESSAGE (' global.menu_id = ' || global.menu_id );
    SYNCHRONIZE; Hope this helps...
    Regards,
    Abdetu...

  • Erase All Content and Settings, continually says the certificate for this server is invalid

    Erase All Content and Settings, continually says the certificate for this server is invalid..
    How can I over come this problem

    Welcome to the Apple Community Siobhan.
    Please try the following...
    Go to Settings > iCloud > Delete Account (This removes your data from your device, but not from your account, it will be added back later).
    Restart the device.
    Sign in again (Settings > iCloud, don't use the 'Create New Apple ID' button).

  • How do I change my iCloud Account email?  I keep getting prompted to enter a password associated with an old email account I no longer use. I do not have the password for it.  How do I change my iCloud Account?

    How do I change my iCloud Account email?  I keep getting prompted to enter a password associated with an old email account I no longer use. I do not have the password for it.  How do I change my iCloud Account?

    You can't delete an existing account, you can only choose to stop using it.  It will still be there should you decide to use it again in the future.

  • Can I use my norwegian iPhone 4 in the US for a few weeks?

    Can I use my norwegian iPhone 4 in the US for a few weeks?

    So I have lived in Daegu, South Korea for 9 months now. And our iphones work perfectly.
    Thankfully we didn't sell our phones in NZ, I had a look online and NZ doesn't lock IPhones to their networks like other countries.
    We went to SKT (in Daegu / National University of Ed) and bought new simcards for $10 each.
    Then signed up for contract / plans.
    We pay roughly $50 a month for unlimited data, 200 minutes, 600 text messages.
    It costs $9 to roam overseas a day.
    We've managed to travel to Japan and Hongkong using our South Korean sims.
    It' been pretty succesful for us.
    All I can say is, do heaps of research peeps, and don't stress :-)

  • HT4427 how do I use a song from iTunes as the ringtone for my iPhone 5?

    how do I use a song from iTunes as the ringtone for my iPhone 5?

    Google will find several free ways to create ringtones for iphone.

  • I used my military (.mil) address as the backup for my appleID account, but now that I need to open the verification email from apple, the .mil doesnt allow me to open and verify that I am who I am?

    I used my military (.mil) address as the backup for my appleID account, but now that I need to open the verification email from apple, the .mil doesnt allow me to open and verify that I am who I am?

    Hey Edgew7,
    Thanks for the question. The following resource may provide a solution:
    iOS 7: If you're asked for the password to your previous Apple ID when signing out of iCloud
    http://support.apple.com/kb/ts5223
    3. Change your Apple ID temporarily
    If signing out and back in to iMessage or FaceTime didn't work, try these steps:
    1. Change your Apple ID to the Apple ID you used previously. You shouldn't need to verify the email address.
    2. Tap Settings > iCloud and try to sign out.
    3. Change your Apple ID to the new email address that you want to use. You'll need to verify the email address.
    4. Tap Settings > iCloud and sign in with the new Apple ID.
    Thanks,
    Matt M.

  • Can anyone tell me what the names for the apps that apear in the new tv ad "learn" ???

    can anyone tell me what the names for the apps that apear in the new tv ad "learn" ???

    Go here -> http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewMultiRoom?fcId=376895159

  • Is it possible to use a variable in the name of other variables?

    Trying to avoid a long post; is there some command in Java that would allow a variable to be read before the rest of the statement it is in?
    For example, using a pair "@" to encapsulate a variable with the mystery command I'm looking for:
    *public class Example {*
    *public static void main (String[] args) {*
    Char variable = "A";
    int @variable@_Status = 0;
    So that this application would create an integer named "A_Status" and assign it a value of 0. Obviously, I'm not looking to be told that "int A_Status = 0" is the best way to do that, I'd like "variable" to be able to be defined by input or change somehow in the code. I have a gut feeling that this is impossible due to the compiler, but I'd like a more professional opinion. Anyone?

    The variable "name" is a lot less important than you think. In fact, when your code is compiled, the computer doesn't care one jot about the name of the variable.
    You should not worry about trying to do this, but rather should tell us the reason why you would even want this. If we knew that, we could show you a better way, guaranteed.

  • Related Content does not display on the name change page

    Hi all,
    Currently, i am doing some research for the related content. I find that delivery configuration has been on the Name Change component (self service). Then I do the security configuration but the related content option does not display on the name change component. No idea which step next i should take.
    Please advise.
    Any reference or docs is also welcomed.
    Dennis

    Hi,
    What do you mean by my two nodes are all local.
    Are you trying to use Related Content within one environment?
    Make sure you have an authentication domain set on your webprofile and that your hosts file reflects this.
    Make sure there is no proxy or firewall in the way.
    Make sure Integration Broker is setup correctly.
    Try pinging your server including the authentication domain.
    Try looking for log files in the application server and errorLog.html in the Webserv folder.

Maybe you are looking for

  • Display value in detail portion different than in table

    I'm saving a 1 character value in a table via a form. I'd like to display a longer description of that item in another item when the master item is selected and the execute_query commands runs for the detailed portion of the form. Is there anyway to

  • Unable to open D3 NEF in CS3 (Mac) and CS2 (Win)

    I have installed the latest Camera Raw Update file (Mac OSX 10.5.3), but when I try to open a nef-file that was taken with my Nikon D3, CS3 complains about an invalid file type - ??? Opening the same file in Nikon NX works without a problem. A friend

  • Connection Pool Questions

    I have a JSP/Servlet application I am developing. I would like to create one OraclePooledConnection for the application. I then have a set of repository classes(CommonRepository, EmployeeRepository, etc) that access the database and create JavaBeans

  • Dynamic Source location using FIle Adapter

    Hi Experts, I having a scenario of file to file, my problem is how can I configure the comm channel to where the file will be pulled wherein the path is defined during the runtime process in certain ABAP program(defined from selection screen)? Is it

  • How to include the NIWebAppServer.conf when building a web service installer in LV2010

    Hi all, I'm build a LabVIEW 2010 web service and creates a deployable setup installation as described in Web Services FAQ: http://zone.ni.com/devzone/cda/tut/p/id/7747#toc12 but also would like to include my .conf file for the NI Application Web Serv