java八大基本数据类型,都有与之对应的包装类
包装类能够实现实体化处理对象,有更多方法来处理当前的数据
整型类型:byte short int long
浮点类型: float double
字符型: char
布尔类型: boolean
int ==> Integer byte ==> Byte
short ==> Short long==>Long
float==>Float double==>Double
char==> Character boolean==>Boolean
[重点]:
-
jdk1.5之后,有自动拆箱和自动装箱
自动装箱: 将基本数据类型转为包装类
int i = 30; Integer i1 = i;
自动拆箱: 将包装类转为基本数据类型
-
***Value () ; 将包装类转为基本数据类型 手动拆箱(了解)
-
toString(); 将基本是数据类型转为字符串
-
parse***(); 将一个字符串 转为所对应的基本数据类型
package com.qf.baozhuang; public class Demo01 { public static void main(String[] args) { // a(); // b(); //c(); //d(); e(); } public static void a(){ //一个持有最大值一个 int可以有2 31 -1。 System.out.println(Integer.MAX_VALUE); //的常量保持的最小值的 int可以具有,-2 31。 System.out.println(Integer.MIN_VALUE); } public static void b(){ //1.自动装箱: 将基本数据类型转为包装类型 int i = 10; Integer j = i; System.out.println(j);//10 System.out.println(j.hashCode());//返回这个 Integer的哈希码 10 //2.自动拆箱: 将包装类转为基本数据类型 int i1 = j; System.out.println(i1);//10 } public static void c(){ //3.toString方法 String s = Integer.toString(55); System.out.println(s); } public static void d(){ //4.将字符串转为基本数据类型 int i = Integer.parseInt("789"); System.out.println(i);//789 double v = Double.parseDouble("789.466"); System.out.println(v);//789.466 } public static void e(){ Integer q1 = 50; Integer q2 = 50; System.out.println(q1 == q2); //true Integer o1 = 129; Integer o2 = 129; //面试考题 因为Integer的数值范围是-128~127;这是在一个数组内 //超出这个范围值的话,就会new一个空间,地址将不一样 System.out.println(o1 == o2); //false } }
文章介绍了Java中的八大基本数据类型与其对应的包装类,包括整型、浮点型、字符型和布尔型。Java1.5以后支持自动装箱和自动拆箱,例如`inti=30;Integeri1=i;`和`inti1=j;`。此外,还展示了如何使用`toString()`方法将数值转换为字符串,以及`parseInt()`和`parseDouble()`方法将字符串转换回基本数据类型。在内存管理方面,文章指出Integer对象在-128到127之间的缓存,导致相同值的Integer对象可能相等,而超出此范围则会创建新的对象,可能导致不等。
1144

被折叠的 条评论
为什么被折叠?



