What is the difference between byte [] and list in Java?

Both can be used to create byte lists But what's the difference between them?

byte[] buffer;
List<Byte> buffer;

Solution

No, first create a byte array The second defines a byte list, which may or may not be supported by the array, depending on the list implementation you use

Arrays are fixed size and pre allocated; If you need to grow the array, you need to create a new larger array, copy the contents, and then add new contents

On the other hand, lists are usually dynamic, growing as content is added to them, shrinking as content is removed from them, and so on An ArrayList implements this by maintaining a backup array. There is usually some slack, and then it is reallocated and copied as needed when adding

Also note that the list cannot actually contain the original byte value; Instead, it will contain byte objects (via a auto@R_802_2419 @Ing process)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>