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?

+3


source to share


2 answers


You will find the following result here :



Minimum string memory usage (bytes) = 8 * (int) ((((no characters) * 2) + 45) / 8)

+6


source


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).

0


source







All Articles