• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating array to hold long range values

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean with "long range"? Can you give a more detailed example of what you're trying to do (actual code)?
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to use a 2 dimensional array.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic