Memory size of String array storing binary codes
I want to store a list of binaries in a String [] array like in the following example ...
String[] str={"10001", "100101","101010101"};
How much memory is required to store the array?
You will find the following result here :
Minimum string memory usage (bytes) = 8 * (int) ((((no characters) * 2) + 45) / 8)
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).