In与Integer的区别:
1. int为原始类型,integer为引用类型且作为in的包装类,就是把in包装成object对象,他是java为int提供的封装类
2. boolean – Boolean char ---- Char byte--- Byte short---Short int---integer
long----Long double -----Double(除了int类型其他均为首字母大写)
3. 例子:Integer i = new Integer(“1234”) ;//字符型转int型
4. int compareTo to(Object o)与其他类比较,如o类也为int型则执行方法2的操作
5. parseInt(String s)将s转为十进制的整数,parseInt(String s,int radix)与之前的一个比多了一基数,就是转为几进制的,radix可以为2,10,16等
6. int s =Integer.parseInt("1110",2); s为:14
7. int s =Integer.parseInt("1110",10); s为:1110
//工具类转换类型(年月日,int,Double,BigDecimal,性别)
package tast;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
//工具类转换类型
public class TypeTools {
SimpleDateFormat sdf = new SimpleDateFormat("mmHHyyyy");
SimpleDateFormat format = new SimpleDateFormat(
"yyyyMMddHHmmss");
//转换BigDecimal金额
public static BigDecimal getBigDecimal(String s) {
if (Pattern.matches("^\\d+\\.??\\d+$", s)) {
return new BigDecimal(s);
}
return null;
}
//转换int型
public static int getInt(String s) {
if (Pattern.matches("^\\d*$", s)) {
return Integer.parseInt(s);
}
return 0;
}
//转换double型
public static Double getDouble(String s) {
if (Pattern.matches("^\\d+.??+\\d*$", s)) {
return Double.parseDouble(s);
}
return null;
}
//转换标准日期
public static Date getDate(String s) {
SimpleDateFormat sdf = new SimpleDateFormat("mmHHyyyy");
try {
Date date = sdf.parse(s);
return date;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//转换字符串日期
public static String getStringDate(Date d) {
SimpleDateFormat sdf = new SimpleDateFormat("mmHHyyyy");
if (d != null) {
return sdf.format(d);
}
return "";
}
// parse(String source)
从给定字符串的开始解析文本,以生成一个日期。
public static Date parseDate(String time) {
try {
return format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
//性别判断
public static String sexParse(String sex) {
return "1".equals(sex) ? "男" : "女";
}
}