Java is not a structured language. It is object oriented and we lack the structurs in one or another way.
In C++, we can create an object array easily and can able to assign the variables so easily, even assigning the values of the member variables of an object array.
In java, we will encounter NullPointerException if we try to assign value to an member variable directly. The solution is to create a temporary object of that particular object and assign the values in to the temporary object. After this we can assign the temporary object into the array.
For example,
class OArray
{
int a;
char c;
}
class OArrayAccess
{
OArray o = new OArray; //temporary object
OArray[] oa = new OArray[10];
//assigning values in to the temp' object
o.a = 10;
o.c = 'k';
//assigning values in to object array
oa[0] = o;
//temp' object is assigned to the object array
}
In order to retrive the values, we have to again assign the array object in to a temporary object and access the values.
The thought of using the vector classes will help only when we deal with different instances of a class. In the case of same object in an oops environment, Object array is the only solution.