Memory size of String array storing binary codes
If you want to store this data more efficiently, your best bet is to store it in a numeric array, for example int[]
. Using an array String[]
, each character uses at least 2 bytes of memory (for example, 1010 will use at least 8 bytes of memory), whereas storing a value in an array int[]
allows you to store a lot more binary numbers without adding extra bytes.
For a simple comparison, one int
is 4 bytes. If you store a binary value int
as String
, it will use 64 bytes (since there are 32 bits in 4 bytes and each "bit" is stored as a 2 byte long Unicode character).
source to share