Solved

arrays

Posted on 2004-10-09
3
165 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 93
ejb stateless example 2 68
Java class and jar 3 61
Bitwise and to sum elements 2 52
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

739 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