This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Extracting INT value from  a  STRING Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Extracting INT value from  a  STRING" Watch "Extracting INT value from  a  STRING" New topic
Author

Extracting INT value from a STRING

Brett Swift
Ranch Hand

Joined: May 22, 2002
Posts: 61
I'm trying to figure out how to extract an int value from the command line. It came up in my head as something you'd think to be fundamental, but I can't figure it out!?!
I've tried parseInt(args[0]); valueOf(args[0]); but maybe I've got the syntax wrong. (not too familiar with those methods.. probably using them wrong!) Anyone have any tips? Thanks!
Brett
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
pareInt is a static method of Integer, so just use this:

That should do the trick. Of course, you'll probably want to catch a NumberFormatException (which is a runtime exception) in the case that the first argument isn't a valid int.
Corey


SCJP Tipline, etc.
Brett Swift
Ranch Hand

Joined: May 22, 2002
Posts: 61
thanks.. I now remember having this problem before and all it was ....was forgeting to reference the Integer class in front of the method call!
Thanks!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Extracting INT value from a STRING
 
Similar Threads
Finding maximum value from command line arguments.
The Art & Science of Java Chapter 4 Exercise 5 AverageList.java
Array Code Help
Number Formatting
Palindorme no.