How can I convert a String to an Int?

J

John Smith

Hi Java-Coder!

I'am coding in Java for about an half year, but I still don't know how I
convert a String to a Int.
Can you help me?

Thanks a lot!
 
J

Jacob

John said:
I'am coding in Java for about an half year, but I still don't know how I
convert a String to a Int.
Can you help me?

try {
int value = Integer.parseInt (string);
}
catch (Exception exception) {
// It wasn't a number after all
}
 
A

Aquila

John said:
Hi Java-Coder!

I'am coding in Java for about an half year, but I still don't know how I
convert a String to a Int.
Can you help me?

Thanks a lot!

String myString = "42";
Integer myInt = newInteger(myString);
 
M

Madhur Ahuja

John Smith said:
Hi Java-Coder!

I'am coding in Java for about an half year, but I still don't know
how I convert a String to a Int.
Can you help me?

String piStr1 = "3";
int pi1 = Integer.valueOf(piStr).intValue();
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top