Issue
How might you go about creating a List of byte[]
(not Byte
)?
I want something like the following:
byte[] deb = new byte[Byte.MIN_VALUE];
List<byte[]> begin = new LinkedList<>();
begin.add(deb);
Solution
That will work fine because arrays are objects in Java, so you can build List
s out of them.
Note that only in Java 7 can you do
List<byte[]> begin = new LinkedList<>();
In older versions you must restate the byte[]
:
List<byte[]> begin = new LinkedList<byte[]>();
This has been brought up already but I'll just reiterate it here. Byte.MIN_VALUE
is less than 0
; you cannot create an array of length less than 0
(it results in a runtime error, specifically a NegativeArraySizeException
). Did you mean Byte.MAX_VALUE
?
Answered By - arshajii
Answer Checked By - Cary Denson (JavaFixing Admin)