| | |
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 |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows







Use that as masijade said.