您的位置:首页 > 其它

Integer包装类的重要方法

2017-03-25 12:26 253 查看

parseInt

public static int parseInt(String s, int radix)throws NumberFormatException
public static int parseInt(String s) throws NumberFormatException


查阅JDK源码可以发现该函数的作用是把字符串转换成Int类型的整数

输入要求:

字符串不能为空;不能输入一位只包含正负号的字符串;除开第一位,其余位只能是数字

radix是进制数,默认是10,要求大于2且小于36

valueof

public static Integer valueOf(int i)
public static Integer valueOf(String s, int radix) throws NumberFormatException
public static Integer valueOf(String s) throws NumberFormatException
这个函数的作用是把输入字符串、int整型转换成指定进制的Integer类型

intValue

Integer a = new Integer(3);
a.intValue();
public int intValue() {
return value;
}
该函数的作用是把Integer对象转换成int

toBinarySting

返回int的二进制表示
System.out.println(Integer.toBinaryString(-7));
11111111111111111111111111111001
写出Integer类中的toBinaryString()方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: