Why we use new byte[1024]?


#1

In this chapter has an line
byte[] buffer = new byte[1024];
Why it need? why 1024 byte and so on? Can you help me?


#2

I don’t have the book, and I don’t do Android.

Now back to the question asked.

From the available information I can tell that the code is about to read something from the network. For this, the code needs a buffer large enough (1024 bytes is large enough? can’t tell.) to store the data it reads.

Hence the line of code:

byte[] buffer = new byte[1024];

Creates that buffer.

You can learn coding and become a competent programmer faster than you can imagine: Learn coding Pretty Function way.