Solved

arrays

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Restore security prompts not working 10 123
Is there a simpler dropbox system? 10 44
junit as external jar or library 7 37
learn programming 8 66
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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