aspose file tools*
The moose likes Beginning Java and the fly likes creating array to hold long range values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating array to hold long range values" Watch "creating array to hold long range values" New topic
Author

creating array to hold long range values

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I want to create a byte array to hold long range values.Can anyone tell me how to do this.

byte byteArray[] = new byte[//here it is expecting int but i want to put long range here];

Can anyone suggest something.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

What do you mean with "long range"? Can you give a more detailed example of what you're trying to do (actual code)?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
if i write byte byteArray = new byte[10] , then byteArray can have maximum 10 bytes.So,like this,we can specify a maximum of 32767 , because that is maximum range of integer.
that is ,

byteArray = new byte[32767] will be valid,
but
byteArray = new byte[1000000] is not valid as we are trying to reserve space for 10 lakh bytes.

So, how can we reserve space for 10 lakh bytes.
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
10 lakh is inside the range and is acceptable.but what if i want to give some value which is out of range.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

One way is to use a 2 dimensional array.


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Originally posted by Raj Kumar Bindal:
if i write byte byteArray = new byte[10] , then byteArray can have maximum 10 bytes.So,like this,we can specify a maximum of 32767 , because that is maximum range of integer. . .


32767 might be the maximum in C but the maximum in Java is 2^31 - 1, which is 21 crore. You might do well to investigate the BigInteger class as an alternative.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating array to hold long range values