# Convert numeric String into Integer (Java)

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

1. ### AzmieGuest

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

What is the best approach?

Azmie, Dec 28, 2003

2. ### SudsyGuest

Integer.parseInt( string );

Sudsy, Dec 28, 2003

3. ### VisionSetGuest

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. ### Thomas SchodtGuest

(Azmie) wrote in
I assume you mean int, rather than Integer

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

PS.
Basic questions like this really belong in c.l.j.help

Thomas Schodt, Dec 28, 2003
5. ### Dan AckroydGuest

String szSomeString = "0000075";

nSomeNumber = Integer.getInteger( szSomeString ) ;

danack

Dan Ackroyd, Dec 28, 2003
6. ### VisionSetGuest

No, getInteger(String s) returns an Integer object,
or throws an exception if s is not parsable

VisionSet, Dec 28, 2003
7. ### Roedy GreenGuest

Roedy Green, Dec 28, 2003
8. ### Andrew ThompsonGuest

Yes please, pretty paper, with a bow! ;-)

Andrew Thompson, Dec 29, 2003
9. ### nosGuest

if(s.equals("000000075")) i=new Integer(75);

nos, Dec 29, 2003
10. ### Andrew ThompsonGuest

.....
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. ### akGuest

...
lol, the biggest if else construct!!!

____________

ak, Dec 29, 2003
12. ### Michiel KonstapelGuest

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

Michiel Konstapel, Dec 29, 2003
13. ### AzmieGuest

Thanks to everyone. the simple way i do this is using parseint function.
Happy new year...

Azmie, Dec 30, 2003