Solved

arrays

Posted on 2004-10-09
3
161 Views
Last Modified: 2010-03-31
Hi,

I have a created a program that will create a single account with the code with the Class being called Account.

Account newAccount = new Account () ;

this is fine but I want to create multiple accounts without coding a new name for each account i.e. newAccount1, newAccount2

what is the syntax for this as I thought it would be something like

Account newAccount[1] = new Account () ;
0
Comment
Question by:Cyart
  • 2
3 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12266340
You should do like this

Account accArray[]=new Account[10];

accArray[0]=new Account();
0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 62 total points
ID: 12266386
Account accArray[]=new Account[someDynamicValue];

for(int i=0;i<accArray.length;i++)
{
accArray[i]=new Account();

//your Acoount related Code here
}
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 63 total points
ID: 12266708
If you don't know how many accounts you are creating ahead of time, you can use the ArrayList class:

ArrayList accountList=new ArrayList();
...
done=false;
while (!done) {
//...Code to get/generate account information
   accountList.add(new Account());
//...
   if (areWeDone())
      done=true;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now