Showing posts with label Conversion. Show all posts
Showing posts with label Conversion. Show all posts

Tuesday, May 22, 2012

Convert String to int

What is the best way to convert the String Object that represents a int value to the primitive type int? Just follow this suggestion, that takes advantage of the parseInt method of the Integer object:

String strValue = "1";
int intValue = Integer.parseInt(strValue);

Convert int to String

What is the best way to convert the primitive type int to a String object?

int intValue = 1;
String stringValue = Integer.toString(intValue);