Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.help Subject: Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Date: Fri, 01 Jul 2011 23:06:25 -0400 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 2 Jul 2011 03:07:00 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="BrOwaJANne849xlH+KPYjQ"; logging-data="28168"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FP+BQVDxv4xseP3/S/doA" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> Cancel-Lock: sha1:TrC+XLfttrn7t7SEHyx0zDQFMzM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:805 On 7/1/2011 1:53 PM, Thee Chicago Wolf [MVP] wrote: > > Doing homework for a programming course and we're given a 1000 digit > String which we have to convert to integer, load into an array, and > then find the largest product of a group of 5 integers. I know I can > use the Integer.parseInt( ) method [...] You'd better hope that most of those digits are zeroes... It seems likely that the homework assignment is intended to make you think about other ways than `int' or even `long' for representing integers. Representations that can handle this sort of count-all-the- protons-in-the-universe-if-every-actual-proton-were-a-universe-itself kind of magnitude. Java provides at least two such things; I think you're being encouraged to discover and use one or both of them. > but I wanted to play around with > the toInt() method. From what I can gather, it's essentially the same > thing...basically the opposite to the toString() method. So, I've > tried a few things and I can't get it to work the way I want. I've never heard of toInt(), and neither has my copy of the Java API documentation. Go back to where you obtained it, and see whether the supplier describes it. > Here's a stripped down version of what I'd like to do. > > public class thousand_digit_string > { > public static void main(String[] args) > { > int oneBigInt=0; > String num = "450"; > oneBigInt = toInt(num); > } > > How can I use it properly? > > I've also seen mention of > > static int toInt(java.lang.String str, int defaultValue) > > and > > NumberUtils.toInt() Check with whoever provided the NumberUtils class. It doesn't come with Java; somebody else must have written it. -- Eric Sosman esosman@ieee-dot-org.invalid