A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
convert string to primitive integer
chinna talluru
Greenhorn
Joined: Jul 23, 2006
Posts: 24
posted
Oct 09, 2006 03:41:00
0
anyone helps me how to convert
String
data type primitive integer
data type
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
Oct 09, 2006 03:56:00
0
public static int stringToInt(String s) { try { return Integer.parseInt(s); } catch (NumberFormatException e) { return 0; // or do your thing. } }
Code depot of a Java EE / JSF developer
|
JSF / Eclipse / Tomcat kickoff tutorial
|
DAO kickoff tutorial
|
I ♥ Unicode
Edwin Dalorzo
Ranch Hand
Joined: Dec 31, 2004
Posts: 961
posted
Oct 09, 2006 06:29:00
0
Another options could be:
int i = Integer.valueOf("100").intValue();
Or simply, if you are using JDK 1.5
int i = Integer.valueOf("100");
Another way could be:
NumberFormat nf = NumberFormat.getIntegerInstance(); int i = nf.parse("100").intValue();
[ October 09, 2006: Message edited by: Edwin Dalorzo ]
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: convert string to primitive integer
Similar Threads
casting confusion
Can we do this?
Wrapper's String Constructor
polymorphism and casting in java??????
int to float conversion
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter