What value should be assigned to an integer type variable, to represent an empty byte array? I need this to store an empty byte array in the database, to represent valueless column in Cassandra.
In general Java terminology, an empty byte array is a byte array with length zero, and can be created with the Java expression new byte[0] .
An array is empty only when it contains zero(0) elements and has zero length. We can test it by using the length property of the array object.
Arrays. fill(). This method assigns the required byte value to the byte array in Java.
A byte in Java is 8 bits. It is a primitive data type, meaning it comes packaged with Java. Bytes can hold values from -128 to 127. No special tasks are needed to use it; simply declare a byte variable and you are off to the races.
According to the Cassandra API http://wiki.apache.org/cassandra/API An empty byte array is
byte[] emptyArray = new byte[0];
In general Java terminology, an empty byte array is a byte array with length zero, and can be created with the Java expression new byte[0]
. According to the accepted answer, the Casandra API uses the standard terminology.
While is is technically possible (see this Q&A) to represent a byte array using an integer typed variable, it wouldn't work here because the Casandra API doesn't support that kind of thing. (And neither should it ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With