I asked this question earlier and got the things clear. However, I have some doubts, explaining below:
Let us assume the need is to have an array with 100 elements in this:
1) Declare array:
Integer[] intArr;
2) Allocate memory for 100 Integer elements and assign the reference to the variable
intArr = new Integer[100];
Now comes the real doubt.
Which one is correct way of assigning values to individual elements within the array:
Approach 1:
intArr[1] = 1;
Approach 2:
intArr[1] = new Integer(1);
My doubt is that we already have allocated memory for 100 elements and if we user Approach 2 , aren't we creating one more memory area and assigning them to the intArr1?
Does intArr[index] hold the reference's address or actual object can be placed in intArr[index].
Hope to get some insight to clear this doubt.