一、 将字符串转成数字
转化过程注意2点:
1.去掉空格。
2.判断字符串是否是数字构成。
private static void parseInt(String intStr) {
//1.去除空格
intStr = intStr.trim();
//2.判断字符串是否为数字
Pattern p = Pattern.compile("-{0,1}\\d{1,}");
Matcher m = p.matcher(intStr);
System.out.println(intStr + "is a num ? " +m.matches());
//3.将字符串解析成数字
int parseInt = Integer.parseInt(intStr);
System.out.println(intStr +" to "+parseInt);
}