01_常见对象(基本数据类型包装类)
- A:基本数据类型包装类
- 将基本数据类型封装成对象,好处在于,对象中能定义方法,进行调用
- B:常用操作
- C:基本类型和包装类的对应
基本类型 | 包装类 |
---|
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
char | Character |
boolean | Boolean |
public class Demo1_Integer {
public static void main(String[] args) {
System.out.println(Integer.toBinaryString(60));
System.out.println(Integer.toOctalString(60));
System.out.println(Integer.toHexString(60));
}
}
- 示例:int – Integer – String 互转
public class Demo2_Integer {
public static void main(String[] args) {
int i = 60;
String s1 = i+"";
System.out.println(s1+60);
String s2 = String.valueOf(i);
System.out.println(s2+61);
Integer j = new Integer(i);
String s3 = j.toString();
System.out.println(s3+62);
String s4 = Integer.toString(i);
System.out.println(s4+63);
String s = "60";
Integer i2 = Integer.valueOf(s);
System.out.println(i2+1);
String ss = "200";
Integer ii = new Integer(ss);
int n = ii.intValue();
int n1 = Integer.parseInt(ss);
}
}