--基本数据类型的包装类
基本数据类型是数据数值
int a = 10;
引用类型是对象引用
String item = "abc";
//http请求中提交的数据[字符串] price = 180 num = 3
String str_price = "180"; //180
String str_num = "3"; //3
//可以使用包装类的方法 字符串-->int 【parse方法\valueOf(s)】
int price = Integr.parseInt(str_price);//
System.out.println(price);//180
int num = Integer.parseInt(str_num);
System.out.println(num);//3
System.out.println(price*num);//540
包装类是基本数据类型的引用类型,提供基本数据类型的数据转换和数据操作的方法。
其实就两个要记住的别的首字母大写即可 一个是Integer和Character
--byte Byte
--short Short
--int Integer
--long Long
--boolean Boolean
--float Float
--double Double
--char Character
-- 十进制转换为二、八、十六进制
// 实现进制的转换 java中默认是十进制
System.out.println(" 十进制转为二进制: " + Integer.toBinaryString(15));// 十进制转为二进制: 1111
System.out.println(" 十进制转为八进制 : " + Integer.toOctalString(15));// 十进制转为八进制: 17
System.out.println(" 十进制转为十六进制: " + Integer.toHexString(15));// 十进制十六进制: f
-- 比较 两个数的大小 前比后大的数是1 后比前大是-1 相等是0
System.out.println("比较两个数的大小:" + Integer.compare(10, 10));// 0
System.out.println("比较两个数的大小:" + Integer.compare(-10, 10));// -1
System.out.println("比较两个数的大小:" + Integer.compare(20, 10));// 1
System.out.println("比较两个数的大小:" + Integer.compare(30, 10));// 1
System.out.println("比较两个数的大小:" + Integer.compare(10, 20));// -1
-- 基本数据类型 包装类【自动装箱、自动拆箱】
Integer priceInt = price;// 自动拆箱:基本数据类型:基本数据类型 封装为包装类
int priceItem = priceInt;// 自动拆箱:包装类转换为基本数据类型
int item = priceInt + 3;
System.out.println(item);// 6
--实现基本数据类型和引用类型之间的转换
--自动装箱 将基本数据类型的数据封装为基本数据类型的包装类
--自动拆箱 将基本数据类型的包装类拆封为基本数据类型的数据
-- 数值格式化异常
double d = Double.parseDouble("12.33");
System.out.println(d);
// 需要在parseDouble中加上" "
// double d1 = Double.parseDouble(12.33);//String类型的包装类无法转换为double浮点数类型
// Exception in thread "main" java.lang.Error: Unresolved compilation problem:
// The method parseDouble(String) in the type Double is not applicable for the
// arguments (double)
//System.out.println(d1);
Double.parseDouble("12.33");// 数值格式化异常:java.lang.NumberFormatException
// Double.parseDouble("12.33b");//数值格式化异常:java.lang.NumberFormatException