I have been trying to make a dynamic array, and it just doesn't work, so I look for help at the internet, but I always see an answer saying that basically Java's array is always fixed, even if you can make it dynamic, you need to do some extra efforts... But then I think, why can't something like this works...
static int objCount = 0;
static int arrayCount = 1;
static Array[] myObject = new Array[arrayCount];
public static void main(String[] args) {
addObject();
addbOject();
for(int i = 0; i < myObject.length; i++)
{
System.out.println(myObject[0].getSomething());
System.out.println(arrayCount);
}
}
public static addObject() {
// Variable instances of var A-C
myObject[objCount] = new Array(varA, varB, varC);
objCount = objCount++;
arrayCount = arrayCount++;
}
My addObject()
method can't record the new object... Isn't it logically feasible...? Like everytimes the addObject()
is invoked, it should increments objCount
and arrayCount
... I'm sure I missed something, any explanation will be much appreciated...
PS : I did give up and use arraylist instead