From e65d4187eebf13118323758fef390b12ac8161c6 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Thu, 29 Jan 2026 10:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E9=98=B6day01-=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E4=B8=8E=E5=9F=BA=E6=9C=AC=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/inmind/wrap08/Demo26.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 javaSE-day01/src/com/inmind/wrap08/Demo26.java diff --git a/javaSE-day01/src/com/inmind/wrap08/Demo26.java b/javaSE-day01/src/com/inmind/wrap08/Demo26.java new file mode 100644 index 0000000..4b9fe1d --- /dev/null +++ b/javaSE-day01/src/com/inmind/wrap08/Demo26.java @@ -0,0 +1,55 @@ +package com.inmind.wrap08; +/* + 在java中定义了8个与基本类型一一对应的包装类 + byte Byte + short Short + int Integer + long Long + float Float + double Double + char Character + boolean Boolean + + 包装类是一个类,封装了很多的功能,提供更多的功能去操作,基本类型进行计算 + + 在jdk1.5版本之后,出现自动拆装箱 + 拆箱:包装类--->基本类型 + 装箱:基本类型--->包装类 + ------------------------------------------------ + 字符串与基本类型的转换 + + 基本类型---->字符串 + +""即可 + 字符串----->基本类型 + 包装类名.parseXXX(字符串); + */ +public class Demo26 { + public static void main(String[] args) { + int i = 10; + Integer i1 = i;//装箱 + Integer i2 = new Integer(10); + System.out.println(i2); + +// int sum = 10+i2;//拆箱 + int sum = 10 + i2.intValue(); + System.out.println(sum); + System.out.println("--------------------------------------"); + //基本类型转为字符串 + int a = 10; + String str1 = a + ""; + + //字符串转为对应的基本类型 + String str2 = "true"; + boolean b1 = Boolean.parseBoolean(str2); + System.out.println(b1); + + String str3 = "100"; + int i3 = Integer.parseInt(str3); + System.out.println(i3); + + String str4 = "2.0"; + double v = Double.parseDouble(str4); + System.out.println(v); + + } +}