[CSC 204] Converting strings to integers

Andrew J. Pounds pounds_aj at mercer.edu
Sun Nov 2 06:40:52 EST 2014


I was asked about the best way to convert a String to an integer.   By 
far the easiest thing to use is the Integer.parseInt method

So if I wanted to convert

String integerAsAString = "  456  "

to

int integerValue = 456;

I could use...


int integerValue = Integer.parseInt(integerAsAString.trim());


-- 
Andrew J. Pounds, Ph.D.  (pounds_aj at mercer.edu)
Professor of Chemistry and Computer Science
Mercer University,  Macon, GA 31207   (478) 301-5627
http://faculty.mercer.edu/pounds_aj

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc204/attachments/20141102/2f4f6432/attachment.html>


More information about the csc204 mailing list