目录
包装类
装箱和拆箱
包装类型和String的转换,包装类的常用方法
包装类
装箱和拆箱
package com.edu.wrapper; public class Interger01 { //演示int<-->Integer的装箱和拆箱 //手动装箱 int n1=100; Integer integer = new Integer(n1); Integer integer01 = Integer.valueOf(n1); //手动拆箱 int i = integer.intValue(); //jdk5后自动拆装 int n2 = 200; Integer integer3 = n2;//底层仍然是Integer.valueOf() int n3 = integer3;//底层仍然是integer.intValue(); }
包装类型和String的转换,包装类的常用方法
package com.edu.wrapper; public class Wrapper02 { public static void main(String[] args) { //包装类-->String Integer i =100; //自动装箱 //方式1 String str = i+""; //方式2 String str1 = Integer.toString(i); //方式3 String str3 = String.valueOf(i); //String-->包装类 String str4 ="123"; Integer integer = Integer.parseInt(str4);//自动转箱 char str5 = 'a'; System.out.println((char)((int)str5-32)); System.out.println(Integer.MAX_VALUE); } }