Possible Duplicate:
How are Integer arrays stored internally, in the JVM?
In C#, when you are creating a new array which is a reference type so it puts a pointer onto Stack and object itself in Heap. If you create this array with simple primitive types such as int
, double
, etc. what it does is to put the values exactly where they are placed in Heap instead of a pointer which points at another heap address where the content of it stored.
So can someone please explain how this happens in Java? Java use Integer
(a reference type) in arrays all the time or treats value types as C# does?
int[] hello = new int[5];
hello[0] = 2; // C# put this value directly in same slot and doesn't
//create a wrapping object.
I know a thing which is called Wrapping Types in Java which C# doesn't have. C# has auto-boxing but Int32
lets say not an reference type, but ValueType
where as Integer
is an object as opposed to int
. You can either box a value using Object o = 5;
or if struct does have a parent class, you can use it too to wrap it up in heap (boxing).