| | |
how to compare a string to an integer in java
![]() |
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
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.
Last edited by darkagn; Mar 11th, 2009 at 6:48 am. Reason: Link error
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. 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).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Need help with T/F and Multiple Choice (Java)
- Searching/Comparing a word in a stack (Java)
- wierd gui/constructor problem (Java)
- java I/O (JSP)
- Creating a "Data" folder in my C: Drive using my Java program (Java)
- Delete button not working on my Java GUI Inventory (Java)
- a for loop problem (Java)
- Something about String.split("-"); problem (Java)
- Need Help with ArrayList sorting (Java)
Other Threads in the Java Forum
- Previous Thread: String search methods indexOf and lastIndexOf
- Next Thread: playlist for media player
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc arguments array arrays automation binary bluetooth bold byte c++ class client code color compare component coordinates count database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list macintosh map method methods mobile netbeans newbie nextline object pong problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads transforms tree web websites windows







Use that as masijade said.