Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #805

Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()?

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.help
Subject Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()?
Date 2011-07-01 23:06 -0400
Organization A noiseless patient Spider
Message-ID <ium20j$rg8$1@dont-email.me> (permalink)
References <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com>

Show all headers | View raw


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

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-01 12:53 -0500
  Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Jeff Higgins <jeff@invalid.invalid> - 2011-07-01 17:55 -0400
  Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-01 18:19 -0700
    Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:26 -0500
      Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 13:39 -0400
        Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 13:57 -0500
          Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 13:01 -0700
            Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 15:47 -0500
              Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 14:57 -0700
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:11 -0500
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 11:54 -0700
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 16:58 -0500
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 15:36 -0700
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-06 16:53 -0700
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 18:07 -0700
              Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-06 09:57 +0100
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:13 -0500
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-07 09:43 +0100
              Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:15 +0200
                Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:14 -0500
          Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 16:27 -0400
            Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:22 +0200
              Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-06 07:33 -0400
  Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-01 23:06 -0400
    Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-01 20:28 -0700
    Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:27 -0500
  Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Roedy Green <see_website@mindprod.com.invalid> - 2011-07-04 08:59 -0700
    Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:30 -0500

csiph-web