This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes string to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string to int" Watch "string to int" New topic
Author

string to int

Andrew Lit
Ranch Hand

Joined: Jul 01, 2002
Posts: 135
hi,
it is very urgent. i've forgotten method that converts string to int. plz remind me. would be very appreciated.
thanks
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
Integer.parseInt()
Volodymyr Shram
Ranch Hand

Joined: Oct 17, 2002
Posts: 47
Originally posted by Andrew Lit:
hi,
it is very urgent. i've forgotten method that converts string to int. plz remind me. would be very appreciated.
thanks

Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
If performance is an issue, the first solution should be chosen.
W.
kumard
Greenhorn

Joined: Mar 06, 2001
Posts: 4
//-----------------------------
public void test1() {
String i = "5";
timer.reset();
for(int j = 0; j < loop; j++) {
int k = Integer.valueOf(i).intValue();
}
timer.print("intValue");
}
//-----------------------------
public void test2() {
String i = "5";
timer.reset();
for(int j = 0; j < loop; j++) {
int k = Integer.parseInt(i);
}
timer.print("parseInt");
}
my test shows
intValue: 173.5
parseInt: 121.9
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: string to int