Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Java has no sizeof. Because I have a list of doubles and ints to store into a ByteBuffer which asks for a size to allocate. With C syntax, I know how to do it like below: 

int size=numDouble*sizeof(double)+numInt*sizeof(int);

Can anyone tell me how to call the size in byte in Java? 

1 Answer

0 votes
by (19.7k points)

From JAVA 8, all primitive types with wrapper classes have BYTES field except Boolean. See the code implementation below: 

int size = numDouble * Double.BYTES + numInt * Integer.BYTES;

For further reference, see this documentation. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 8, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer

Browse Categories

...