Skip to content
Advertisement

Is it possible to create a ByteArray of ByteArrays as elements in kotlin?

I have some issues with creating a ByteArray var where its elements are also ByteArray, I don’t know is it possible first ? and how to ?

Advertisement

Answer

A ByteArray is just what it sounds like, an array of bytes. If you want to hold onto multiple byte arrays you can use a generic list or array.

Something like this:

JavaScript

Based on your more recent comment it seems you may want to add to allByteArray in a loop, if that is the case you can also use an ArrayList like this:

JavaScript

Also as suggested by Alexey Romanov, you could do this in the constructor for a MutableList (or the same thing can be done with a list if it doesn’t need to be mutable) like this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement