Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArrayList size of elements

Status
Not open for further replies.

tenshekels

Programmer
Feb 5, 2004
20
US
Does anyone know how the ArrayList works in regards to sizing of elements? What I mean is if you add 1,000 byte values to an ArrayList does that mean that the ArrayList is then 1,000 bytes long - or does it store each byte as a generic "object" - thus storing it as a 4 bytes each??
 
To answer my own question - the byte value is "boxed" - therefore for each byte you add an "object" and a "byte" to the heap (the "object" is a reference to the "byte" value).

So an array instance of 1,000 "bytes" would occupy 5,000 bytes on the heap.
 
Someone else informed me...

"Actually, you'd end up taking more than that - 4 bytes for the actual value, 8 bytes (IIRC) object overhead, and 4 bytes for the reference in the ArrayList. Basically, you don't want to be doing that... "
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top