please inform a newb  
Author Message
Stephen Mayes





PostPosted: 2005-3-25 4:17:00 Top

java-programmer, please inform a newb class A{
class B{
boolean flag;
int value;
}
B b[] = new B[10];
public A(){
for (int i = 0; i < 10; i++)
b[i] = new B();
}
}

I'm wondering if there is a more elegant way to instantiate the elements of
b[] than the 'for' loop.


 
E.Otter





PostPosted: 2005-4-4 3:36:00 Top

java-programmer >> please inform a newb Instead of setting the size of the array
B b[] = new B[10];

Set the size and add all 10 objects at all once.
B b[] = new B[] {new B(), new B(), new B(), new B(), new B(), new B(), new
B(), new B(), new B(), new B() };


"Stephen Mayes" <email***@***.com> wrote in message
news:2aF0e.52276$email***@***.com...
> class A{
> class B{
> boolean flag;
> int value;
> }
> B b[] = new B[10];
> public A(){
> for (int i = 0; i < 10; i++)
> b[i] = new B();
> }
> }
>
> I'm wondering if there is a more elegant way to instantiate the elements
of
> b[] than the 'for' loop.
>
>