Daniel Pitts schrieb:
puzzlecracker wrote:
Item 25 of Effective Java 2nd Edition (Bloch): Prefer lists to arrays.
Lists are a higher level abstraction, and therefor "easier" to work with.
and slower to work with...
Premature optimization is the root of all evil.
Lists are marginally slower to work with than arrays, but who cares if your
program is fast when it doesn't work correctly?
Until now the only reason to optimize collections away for arrays was never
the speed but allways the RAM usage for me.
If you know that you will be holding about 100k to 1 Mio collections .. then
the overhead of the collections is enormous an using arrays becomes a must.
ie
HashSet 1 obj holding an hashmap 12byte
HashMap 1 obj holding 8 Byte
3*int+1 float 16
entry array+map entrys 8+n*4 + n*Entry bytes
Entry: 8 Bytes
+ 3 object references 12 Byte
+ 1 int 4 Byte
so hashset:
44+ n*28 byte
(due to the load factor of the hasmap it would be even some bytes more..)
in comparison to just an array: 8+ n*4 bytes