Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing empty byte array through an Int variable?

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.

like image 731
Rajat Gupta Avatar asked Feb 26 '11 05:02

Rajat Gupta


People also ask

How do you declare an empty byte array?

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] .

How check if byte array is empty?

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.

How do you assign a byte array in Java?

Arrays. fill(). This method assigns the required byte value to the byte array in Java.

What is byte [] 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.


2 Answers

According to the Cassandra API http://wiki.apache.org/cassandra/API An empty byte array is

byte[] emptyArray = new byte[0];
like image 186
Mohamed Mansour Avatar answered Oct 24 '22 07:10

Mohamed Mansour


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 ...)

like image 11
Stephen C Avatar answered Oct 24 '22 06:10

Stephen C