I have a class in Java which has 2 fields like
Class A
{
int i;
double v;
}
I make an array of object of class A like:
A[] x = new A[3];
After assigning the memory to object I assign value to object like:
A[0].i = 1;
A[0].v = 2.5;
A[1].i = 2;
A[1].v = 3.5;
A[2].i = 55;
A[2].v = 1.5;
I was wondering it there was a better way to initialize the object-values.
Yes: use constructors:
Update: wrt. to comment below: