1. Java integers are 32 bits.
2. Java Strings are 16 bits per character
3. To compare them or use the String in arithmetic expressions, you first need to convert the string to integer with something like int i = new Integer("12345");
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
An int is 4 bytes which is 32 bits (31 of which is value and the 32nd is a pos/neg toggle). A long is 8 bytes (63 bits data and 1 pos/neg toggle) so use long and parse that String to a long using Long.parseLong(string). If a long is also not large enough use the BigDecimal class. See the API docs.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
An integer in Java is a 32-bit number. If you need anything larger than that, I suggest you look at the Math.BigInteger class. Documentation for a BigInteger can be found here .
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
Looks like James, masijade and I all posted at the same time, and I forgot about the long type :$ Use that as masijade said.
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
and since you're working with String-objects, make sure they're valid numeric values before you try to compare them :)
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
Ach, yeah, and as darkagn say, BigInteger, not BigDecimal (unless you're going to have decimals, in which case you'd have been using float and double instead of int and long, anyway).
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
Yes, long is necessary if your values can exceed 2^31 (although I suspect your example loop was just an example; you don't really want to execute a loop that many times!).
If your String isn't valid for converting to integer (or long) you'll get a NumberFormatException thrown.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Leave your lame chat-speak at the door. Read the forum rules on this.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Are you talking about integers of more than 10 bytes ..like 12345678910228377466464678262737867865786826868326???
@Ezzaral
Are you happy ???
Yes, much better. That wasn't so hard, was it?
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847