Convert numeric String into Integer (Java)

Discussion in 'Java' started by Azmie, Dec 28, 2003.

  1. Azmie

    Azmie Guest

    Anyone can help me to solve this problem.
    I want to convert numeric string = "000000075" into Integer value = 75

    What is the best approach?

    Thanks in advance.
    Azmie, Dec 28, 2003
    1. Advertisements

  2. Azmie

    Sudsy Guest

    Integer.parseInt( string );

    Suggestion: read the javadocs.
    Sudsy, Dec 28, 2003
    1. Advertisements

  3. Azmie

    VisionSet Guest

    All you need to do is browse java.lang.Integer in the API docs for about 30
    seconds to arrive at the answer...

    int i = Integer.parseInt("00000075");

    or if you'd like that wrapped

    Integer i = Integer.valueOf("00000075");
    VisionSet, Dec 28, 2003
  4. (Azmie) wrote in
    I assume you mean int, rather than Integer

    String s = "000000075";
    int n = Integer.parseInt(s);

    Basic questions like this really belong in
    Thomas Schodt, Dec 28, 2003
  5. Azmie

    Dan Ackroyd Guest

    String szSomeString = "0000075";
    int nSomeNumber;

    nSomeNumber = Integer.getInteger( szSomeString ) ;

    nSomeNumber now equals 75....

    Dan Ackroyd, Dec 28, 2003
  6. Azmie

    VisionSet Guest

    No, getInteger(String s) returns an Integer object,
    or throws an exception if s is not parsable
    VisionSet, Dec 28, 2003
  7. Azmie

    Roedy Green Guest

    Roedy Green, Dec 28, 2003
  8. Yes please, pretty paper, with a bow! ;-)
    Andrew Thompson, Dec 29, 2003
  9. Azmie

    nos Guest

    nos, Dec 29, 2003
  10. .....
    else if (s.equals("00000075")) i=new Integer(75);
    else if (s.equals("000075")) i=new Integer(75);
    else if (s.equals("00075")) i=new Integer(75);
    else if (s.equals("0075")) i=new Integer(75);
    else if (s.equals("075")) i=new Integer(75);
    else if (s.equals("75")) i=new Integer(75);
    else if (s.equals("00000076")) i=new Integer(76);
    Andrew Thompson, Dec 29, 2003
  11. Azmie

    ak Guest

    lol, the biggest if else construct!!!

    ____________ the best java image reader.
    ak, Dec 29, 2003
  12. String szSomeString = "0000075";
    Nope, getInteger(String s) uses s as the name of a system property and
    creates an Integer (or null) from its value. Does anyone actually use these
    methods, like Integer.getInteger() and Boolean.getBoolean()?
    Michiel Konstapel, Dec 29, 2003
  13. Azmie

    Azmie Guest

    Thanks to everyone. the simple way i do this is using parseint function.
    Happy new year...
    Azmie, Dec 30, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.