Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

arrays

Posted on 2004-10-09
3
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 248 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 252 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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