Convert numeric String into Integer (Java)

A

Azmie

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.
 
S

Sudsy

Azmie said:
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.

Integer.parseInt( string );

Suggestion: read the javadocs.
 
V

VisionSet

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

What is the best approach?

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");
 
T

Thomas Schodt

(e-mail address removed) (Azmie) wrote in
I want to convert numeric string = "000000075" into Integer value = 75

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
 
D

Dan Ackroyd

String szSomeString = "0000075";
int nSomeNumber;

nSomeNumber = Integer.getInteger( szSomeString ) ;

nSomeNumber now equals 75....

danack
 
V

VisionSet

Dan Ackroyd said:
String szSomeString = "0000075";
int nSomeNumber;

nSomeNumber = Integer.getInteger( szSomeString ) ;

nSomeNumber now equals 75....

danack

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

Andrew Thompson

nos said:
...
if(s.equals("000000075")) i=new Integer(75);
.....
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);
......
 
A

ak

...
75
....
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);

lol, the biggest if else construct!!!

____________

http://reader.imagero.com the best java image reader.
 
M

Michiel Konstapel

String szSomeString = "0000075";
No, getInteger(String s) returns an Integer object,
or throws an exception if s is not parsable

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
 
A

Azmie

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

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top