Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!news.belwue.de!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Lothar Kimmeringer Newsgroups: comp.lang.java.help Subject: Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Date: Wed, 6 Jul 2011 11:22:45 +0200 Organization: Organization?! Only chaos here! Lines: 35 Message-ID: <10ygcvt3gwxo3.dlg@kimmeringer.de> References: <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> <7an6179km7upsvba40ebe98gmfedg2414k@4ax.com> Reply-To: news@kimmeringer.de NNTP-Posting-Host: mnch-5d85dbee.pool.mediaways.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: online.de 1309944165 9853 93.133.219.238 (6 Jul 2011 09:22:45 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Wed, 6 Jul 2011 09:22:45 +0000 (UTC) User-Agent: 40tude_Dialog/2.0.15.1de Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:826 Eric Sosman wrote: > On 7/5/2011 2:57 PM, Thee Chicago Wolf [MVP] wrote: >> The limit is because you can't >> convert a string of numbers to int past 9 digits or it bombs out. > > ... and it depends on which nine digits, too: "111111111" is > just fine as an `int', while "555555555" is not. Objection, your honor ;-) > I imagine that > your homework exercise is intended to bring you to an understanding > of this limitation, and also intended to introduce you to other > ways of representing integers than as `int' values. In that case I wouldn't use 1000-digit numbers but numbers with 10 digits, where some of them are below 2^31 and some are higher to let the parseInt-method fail. > Two methods, surely. And I hope by now you understand that > integer-to-string is a far simpler matter than string-to-integer. toString() is simple indeed but in real life scenarios you often need to format it in a human readable way, so I18N comes into place, complicating things. Regards, Lothar -- Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81) Always remember: The answer is forty-two, there can only be wrong questions!