Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.help Subject: Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Date: Wed, 06 Jul 2011 11:54:47 -0700 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> <7an6179km7upsvba40ebe98gmfedg2414k@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 6 Jul 2011 18:54:52 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="5HSAJfqnDjjLFxXZ6WBWEw"; logging-data="2302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Y/Tl6NqwilkgqE6+TCkoJa+2xu4rxxqs=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: Cancel-Lock: sha1:ZsQ815+MKnLifOMsL+CIm5oXcl8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:831 On 7/6/2011 11:11 AM, Thee Chicago Wolf [MVP] wrote: > String str = "30420729485092847590"; > int[] x = new int[20]; > > for (int i = 0; i< str.length(); i++) > { > String index = str.charAt(i)+""; > x[i] = Integer.parseInt(index); > } The problem here is that you've switched requirements again. Your first problems statement was: > find the largest product of a group of 5 integers. And those aren't integers, they're digits. So it all depends still on what you are trying to do. If you just want the digits: String str = "30420729485092847590"; int[] x = new int[ str.length ]; // *cough* for (int i = 0; i < str.length(); i++) { x[i] = str.charAt(i) - '0'; } No need to parse a single digit.