Lecture 23
20
Conversions
•
Strings have no meaning: “1001” is not
1001
•
To convert a String to an integer:
–
int n;
–
String s = “1001”;
–
try {
–
n = Integer.parseInt(s);
// String
®
int
–
}
–
catch (NumberFormatException e) {
–
// take corrective action
–
}
–