Edit
基本数据类型对象包装类_Integer
1.基本数据类型对象包装类
2.byte Byte
3.short Short
4.int Integer
5.long Long
6.boolean Boolean
7.float Float
8.double Double
9.char Character
10.
11.如:整数类型的最大值:Integer.MAX_VALUE
类型转换
1.基本数据类型转成字符串
基本数据类型转成字符串,toString是静态方法,所以直接类名直接调用
String s = Integer.toString(32);//将34整数转换成”34”
String s = Long.toString(6554);//将6554长整形数转换成”6554”
String s = Boolean.toString(true);//结果为”true”
String s = 基本数据类型.toString(基本数据类型值)
非静态方法,建立对象调用
Integer i = new Integer(“123”);
int num = i.intValue();
2.字符串转成基本数据类型
字符串转成基本数据类型,parseInt()方法也是静态方法,也直接类名调用
int i = Integer.parseInt(“65”)
boolean b = Boolean.parseBoolean(“true”)
double d = Double.parseDouble(“5555454”)
3.十进制转换成其他进制
十进制转换成其他进制,下面的方法也是静态方法
Integer.toBinaryString(6);//转成二进制,结果是110
Integer.toHexString(60);//转成十六进制,结果是3c
4.其他进制转换成十进制
其他进制转换成十进制,下面的方法也是静态方法
Integer.parseInt(String s,int radix)
Integer.parseInt(“110”,10);//将110转成十进制,结果为110
Integer.parseInt(“110”,2);//将110转成二进制,结果为6
Integer.parseInt(“11111101”,16);//转成十六进制
5.JDK1.5版本后出现的新特性
1. Integer x = new Integer(4);
2. Integer x = 4;//自动装箱,等同于上面
3. x = x + 2;//x+2:进行自动拆箱,变成了int类型,和2进行了加法运算,然后在装箱赋值给x,为一个对象
4.
5.
6. Integer m = 128;
7. Integer n = 128;
8. sop(m==n);//结果为false,因为两个不同对象
9. Integer a = 127;
10. Integer b = 127;
11. sop(a==b);//结果为true,因为a,b指向了同一个对象,因为当数值在byte范围内,对于新特性,如果数值已经存在,则不会建立新的对象
12.
程序实例
1.class IntegerDemo
2.{
3. public static void main(String[] args)
4. {
5. int i = Integer.parseInt("65");//这里必须传入的字符串必须是全是数字,如含有字母会报错
6. boolean b = Boolean.parseBoolean("true");
7. System.out.println(b);
8. Integer aa = new Integer("123");
9. int num = aa.intValue();
10. System.out.println(num);
11. method_equals();
12.
13. }
14. public static void method_equals()
15. {
16. Integer x = new Integer("123");
17. Integer y = new Integer(123);
18. System.out.println("x==y:"+(x==y));//因为这里x,y是两两个对象,所有不相等
19. System.out.println("x.equals(y):"+x.equals(y));//Integer类复写了equals方法,比较他们的值是否相等
20. }
21.}
@%2802.%u8D44%u6599%29%5B%20Integer%2C%20Boolean%2C%20Loog%2C%20Character%2C%20%u57FA%u672C%u6570%u636E%u7C7B%u578B%u5BF9%u8C61%u5305%u88C5%u7C7B%2C%20Integer%2C160828%5D%0A%23%u57FA%u672C%u6570%u636E%u7C7B%u578B%u5BF9%u8C61%u5305%u88C5%u7C7B_Integer%0A%60%60%60java%0A%u57FA%u672C%u6570%u636E%u7C7B%u578B%u5BF9%u8C61%u5305%u88C5%u7C7B%0Abyte%20%20%20%20%20%20Byte%0Ashort%20%20%20%20%20Short%0Aint%20%20%20%20%20%20%20Integer%0Along%20%20%20%20%20%20Long%0Aboolean%20%20%20Boolean%0Afloat%20%20%20%20%20Float%0Adouble%20%20%20%20Double%0Achar%20%20%20%20%20%20Character%0A%0A%u5982%3A%u6574%u6570%u7C7B%u578B%u7684%u6700%u5927%u503C%3AInteger.MAX_VALUE%0A%60%60%60%0A%0A%5BTOC%5D%0A%0A%23%23%u7C7B%u578B%u8F6C%u6362%0A%23%23%231.%u57FA%u672C%u6570%u636E%u7C7B%u578B%u8F6C%u6210%u5B57%u7B26%u4E32%0A%3E%u57FA%u672C%u6570%u636E%u7C7B%u578B%u8F6C%u6210%u5B57%u7B26%u4E32%2CtoString%u662F%u9759%u6001%u65B9%u6CD5%2C%u6240%u4EE5%u76F4%u63A5%u7C7B%u540D%u76F4%u63A5%u8C03%u7528%0A%20%20String%20s%20%3D%20Integer.toString%2832%29%3B//%u5C0634%u6574%u6570%u8F6C%u6362%u6210%2234%22%0A%20%20String%20s%20%3D%20Long.toString%286554%29%3B//%u5C066554%u957F%u6574%u5F62%u6570%u8F6C%u6362%u6210%226554%22%0A%20%20String%20s%20%3D%20Boolean.toString%28true%29%3B//%u7ED3%u679C%u4E3A%22true%22%0A%20%20String%20s%20%3D%20%u57FA%u672C%u6570%u636E%u7C7B%u578B.toString%28%u57FA%u672C%u6570%u636E%u7C7B%u578B%u503C%29%0A%0A%20%3E%20%u975E%u9759%u6001%u65B9%u6CD5%2C%u5EFA%u7ACB%u5BF9%u8C61%u8C03%u7528%0A%20%20Integer%20i%20%3D%20new%20Integer%28%22123%22%29%3B%0A%20%20int%20num%20%3D%20i.intValue%28%29%3B%0A%0A%23%23%232.%u5B57%u7B26%u4E32%u8F6C%u6210%u57FA%u672C%u6570%u636E%u7C7B%u578B%0A%3E%u5B57%u7B26%u4E32%u8F6C%u6210%u57FA%u672C%u6570%u636E%u7C7B%u578B%2CparseInt%28%29%u65B9%u6CD5%u4E5F%u662F%u9759%u6001%u65B9%u6CD5%2C%u4E5F%u76F4%u63A5%u7C7B%u540D%u8C03%u7528%0A%20%20int%20i%20%3D%20Integer.parseInt%28%2265%22%29%0A%20%20boolean%20b%20%3D%20Boolean.parseBoolean%28%22true%22%29%0A%20%20double%20d%20%3D%20Double.parseDouble%28%225555454%22%29%0A%0A%23%23%233.%u5341%u8FDB%u5236%u8F6C%u6362%u6210%u5176%u4ED6%u8FDB%u5236%0A%3E%u5341%u8FDB%u5236%u8F6C%u6362%u6210%u5176%u4ED6%u8FDB%u5236%2C%u4E0B%u9762%u7684%u65B9%u6CD5%u4E5F%u662F%u9759%u6001%u65B9%u6CD5%0A%20%20Integer.toBinaryString%286%29%3B//%u8F6C%u6210%u4E8C%u8FDB%u5236%2C%u7ED3%u679C%u662F110%0A%20%20Integer.toHexString%2860%29%3B//%u8F6C%u6210%u5341%u516D%u8FDB%u5236%2C%u7ED3%u679C%u662F3c%0A%0A%23%23%234.%u5176%u4ED6%u8FDB%u5236%u8F6C%u6362%u6210%u5341%u8FDB%u5236%0A%3E%u5176%u4ED6%u8FDB%u5236%u8F6C%u6362%u6210%u5341%u8FDB%u5236%2C%u4E0B%u9762%u7684%u65B9%u6CD5%u4E5F%u662F%u9759%u6001%u65B9%u6CD5%0A%20%20Integer.parseInt%28String%20s%2Cint%20radix%29%0A%20%20Integer.parseInt%28%22110%22%2C10%29%3B//%u5C06110%u8F6C%u6210%u5341%u8FDB%u5236%2C%u7ED3%u679C%u4E3A110%0A%20%20Integer.parseInt%28%22110%22%2C2%29%3B//%u5C06110%u8F6C%u6210%u4E8C%u8FDB%u5236%2C%u7ED3%u679C%u4E3A6%0A%20%20Integer.parseInt%28%2211111101%22%2C16%29%3B//%u8F6C%u6210%u5341%u516D%u8FDB%u5236%0A%0A%23%23%235.JDK1.5%u7248%u672C%u540E%u51FA%u73B0%u7684%u65B0%u7279%u6027%0A%60%60%60java%0A%20%20Integer%20x%20%3D%20new%20Integer%284%29%3B%0A%20%20Integer%20x%20%3D%204%3B//%u81EA%u52A8%u88C5%u7BB1%2C%u7B49%u540C%u4E8E%u4E0A%u9762%0A%20%20x%20%3D%20x%20+%202%3B//x+2%3A%u8FDB%u884C%u81EA%u52A8%u62C6%u7BB1%2C%u53D8%u6210%u4E86int%u7C7B%u578B%2C%u548C2%u8FDB%u884C%u4E86%u52A0%u6CD5%u8FD0%u7B97%2C%u7136%u540E%u5728%u88C5%u7BB1%u8D4B%u503C%u7ED9x%2C%u4E3A%u4E00%u4E2A%u5BF9%u8C61%0A%0A%0A%20%20Integer%20m%20%3D%20128%3B%0A%20%20Integer%20n%20%3D%20128%3B%0A%20%20sop%28m%3D%3Dn%29%3B//%u7ED3%u679C%u4E3Afalse%2C%u56E0%u4E3A%u4E24%u4E2A%u4E0D%u540C%u5BF9%u8C61%0A%20%20Integer%20a%20%3D%20127%3B%0A%20%20Integer%20b%20%3D%20127%3B%0A%20%20sop%28a%3D%3Db%29%3B//%u7ED3%u679C%u4E3Atrue%2C%u56E0%u4E3Aa%2Cb%u6307%u5411%u4E86%u540C%u4E00%u4E2A%u5BF9%u8C61%2C%u56E0%u4E3A%u5F53%u6570%u503C%u5728byte%u8303%u56F4%u5185%2C%u5BF9%u4E8E%u65B0%u7279%u6027%2C%u5982%u679C%u6570%u503C%u5DF2%u7ECF%u5B58%u5728%2C%u5219%u4E0D%u4F1A%u5EFA%u7ACB%u65B0%u7684%u5BF9%u8C61%0A%0A%60%60%60%0A%0A%23%23%u7A0B%u5E8F%u5B9E%u4F8B%0A%60%60%60java%0Aclass%20%20IntegerDemo%0A%7B%0A%09public%20static%20void%20main%28String%5B%5D%20args%29%20%0A%09%7B%0A%09%09int%20i%20%3D%20Integer.parseInt%28%2265%22%29%3B//%u8FD9%u91CC%u5FC5%u987B%u4F20%u5165%u7684%u5B57%u7B26%u4E32%u5FC5%u987B%u662F%u5168%u662F%u6570%u5B57%2C%u5982%u542B%u6709%u5B57%u6BCD%u4F1A%u62A5%u9519%0A%09%09boolean%20b%20%3D%20Boolean.parseBoolean%28%22true%22%29%3B%0A%09%09System.out.println%28b%29%3B%0A%09%09Integer%20aa%20%3D%20new%20Integer%28%22123%22%29%3B%0A%09%09int%20num%20%3D%20aa.intValue%28%29%3B%0A%09%09System.out.println%28num%29%3B%0A%09%09method_equals%28%29%3B%0A%0A%09%7D%0A%09public%20static%20void%20method_equals%28%29%0A%09%7B%0A%09%09Integer%20x%20%3D%20new%20Integer%28%22123%22%29%3B%0A%09%09Integer%20y%20%3D%20new%20Integer%28123%29%3B%0A%09%09System.out.println%28%22x%3D%3Dy%3A%22+%28x%3D%3Dy%29%29%3B//%u56E0%u4E3A%u8FD9%u91CCx%2Cy%u662F%u4E24%u4E24%u4E2A%u5BF9%u8C61%2C%u6240%u6709%u4E0D%u76F8%u7B49%0A%09%09System.out.println%28%22x.equals%28y%29%3A%22+x.equals%28y%29%29%3B//Integer%u7C7B%u590D%u5199%u4E86equals%u65B9%u6CD5%2C%u6BD4%u8F83%u4ED6%u4EEC%u7684%u503C%u662F%u5426%u76F8%u7B49%0A%09%7D%0A%7D%0A%60%60%60