当前位置: 首页 > article >正文

【Java SE】包装类 Byte、Short、Integer、Long、Character、Float、Double、Boolean

参考笔记:java 包装类 万字详解(通俗易懂)_java包装类-CSDN博客

目录

1.简介

2.包装类的继承关系图

3.装箱和拆箱

3.1 介绍

3.2 手动拆装箱

3.3. 自动拆装箱

​4.关于String类型的转化问题

4.1 String类型和基本类型的相互转化

4.1.1 String ——> 基本类型

​4.1.2 基本类型 ——> String

4.2 String类型和包装类型的相互转化

4.2.1 String ——> 包装类

4.2.2 包装类 ——> String

5.八大包装类的常用成员方法

​5.1 Byte类常用方法

5.2 Short类常用方法

5.3 Integer类常用方法

5.4 Long类常用方法

5.5 Character类常用方法 

5.6 Float类常用方法

5.7 Double类常用方法

5.8 Boolean类常用方法

6.Integer创建机制的面试题(重要)

6.1 练习题1

6.2 练习题2


1.简介

基本数据类型不是对象,不能使用类的方法;因此,  Java 针对基本类型提供了它们对应的包装类,八大基本数据类型,对应了八种包装类,以对象的形式来调用。包装类有了类的特点,使得可以调用包装类中的方法

八大包装类位于 java.lang 包下,如下图所示:

除了 IntegerCharacter 这两个包装类外,其他六个包装类的类名均是对应的基本类型首字母大写后得到的

2.包装类的继承关系图

蓝色实线:继承extends

绿色虚线:实现implements

Byte、Integer、Long、Float、Double、Short 的继续关系图

 Boolean 的继承关系图

 Character 的继承关系图

3.装箱和拆箱

3.1 介绍

  • 装箱:基本类型 ——> 包装类型(或者叫对象类型,引用类型)

  • 拆箱:包装类型 ——> 基本类型

3.2 手动拆装箱

JDK5.0 之前,拆装箱均是程序员手动完成的

  • 手动装箱:可以使用包装类的构造器完成,也可以使用 valueOf() 方法

  • 手动拆箱:Integer 类为例,需要用到 intValue() 方法;以 Character 类为例,需要用到 charValue() 方法

案例1:Integer包装类的手动拆装箱过程 

public class demo {public static void main(String[] args) {//JDK5.0之前,拆装箱都是手动完成int temp = 19;//手动装箱(基本类型 ————> 包装/引用类型)Integer integer_0 = new Integer(temp);//使用包装类的构造器完成装箱Integer integer_1 = Integer.valueOf(temp);//使用包装类的valueOf方法完成装箱//手动拆箱(包装/引用类型 ————> 基本类型)int tempI_0 = integer_0.intValue();//使用包装类的intValue方法完成拆箱System.out.println("integer_0的值 = " + integer_0);System.out.println("integer_1的值 = " + integer_1);System.out.println("tempI_0 = " + tempI_0);}
}

 案例1运行结果

案例2:Boolean包装类的手动拆装箱过程 

public class demo {public static void main(String[] args) {//JDK5.0之前,拆装箱都是手动完成char temp = 'a';//手动装箱(基本类型 ————> 包装/引用类型)Character character_1 = new Character(temp);//使用包装类的构造器完成装箱Character character_2 = Character.valueOf(temp);//使用包装类的valueOf方法完成装箱//手动拆箱(包装/引用类型 ————> 基本类型)char tempI_0 = character_1.charValue();//使用包装类的charValue方法完成拆箱System.out.println("character_1的值 = " + character_1);System.out.println("character_2的值 = " + character_2);System.out.println("tempI_0 = " + tempI_0);}
}

 案例2的执行结果

3.3. 自动拆装箱

JDK5.0 开始,Java 提供了自动拆装箱的机制(不需要手动调用构造器或者方法了)

  • 自动装箱:实际上底层调用了 valueOf() 方法

  • 手动拆箱:实际上底层调用了 intValue()方法(以Integer包装类为例)

案例:Integer包装类的自动拆装箱 

public class demo {public static void main(String[] args) {//JDK5.0以后,java提供了自动拆装箱Integer integer_1 = 199;    //(自动)装箱——其实底层调用的仍然是valueOf方法(可Debug)int tempI_1 = integer_1;    //(自动)拆箱——其实底层调用的仍然是intValue方法System.out.println("integer_1的值 = " + integer_1);System.out.println("tempI_1 = " + tempI_1);System.out.println("----------------------------------");}
}

运行结果

Debug验证自动拆装箱是否在底层调用了手动拆装箱时用到的方法:valueOf、intValue

由上面的 GIF 可以看到,自动装拆箱底层分别调用了valueOf() 方法、intValue()方法

另外,关于 IntegervalueOf() 方法源码如下 :

 @IntrinsicCandidatepublic static Integer valueOf(int i) {if (i >= IntegerCache.low && i <= IntegerCache.high)return IntegerCache.cache[i + (-IntegerCache.low)];return new Integer(i);}

源码的 valueOf 方法中有一个 if 条件语句的判断,它的意思是:如果传入的 int 基本类型的值在这个范围内,就不 new 新的 Integer 对象,而是调用底层的用 static final 修饰的 Integer 缓冲数组 cache。通过追溯源码,可以得知这里的 lowhigh 的实际范围是 -128 ~ 127,如下图所示 : 

缓冲数组 cache 中存放的元素是[-128,127]。可以通过 Debug 来看看底层的缓冲数组是否真实存在,如下GIF所示 : 

​4.关于String类型的转化问题

4.1 String类型和基本类型的相互转化

4.1.1 String ——> 基本类型

包装类中的 parseXxx 方法可以将字符串类型的数据转换成对应的基本类型,需要用相应的基本类型来作接收

需要注意的是,在将字符串类型转为其他基本类型前,一定要确认字符串里面的内容能否正常转换,比方说,如果想把 "唱跳rap篮球" 这段字符串转换为 int 类型,这时候一定会发生数字格式异常,如下图所示 :

String  ——> 基本类型演示(byte、short、int、long、float、double、boolean)

public class demo {public static void main(String[] args) {//parseXxx(String),以对应的基本类型作接收byte temp_byte = Byte.parseByte("11");short temp_short = Short.parseShort("141");int temp_int = Integer.parseInt("430");long temp_long = Long.parseLong("11211");float temp_float = Float.parseFloat("66.66F");double temp_double = Double.parseDouble("666.666");boolean temp_boolean = Boolean.parseBoolean("true");System.out.println("temp_byte = " + temp_byte);System.out.println("temp_short = " + temp_short);System.out.println("temp_int = " + temp_int);System.out.println("temp_long = " + temp_long);System.out.println("temp_float = " + temp_float);System.out.println("temp_double = " + temp_double);System.out.println("temp_boolean = " + temp_boolean);}
}

运行结果:

 String  ——> char 演示

在八大包装类中,除了 Character 类外,其他的 7 种包装类中都有 parseXxx 方法。如果想将 String 字符串类型的数据转换成 char 类型的数据,可以通过 String 类中的两个方法来完成:

① char[] toCharArray() : 将字符串转换成字符数组
② char charAt(int index) : 获取指定索引位置的字符

public class demo {public static void main(String[] args) {//定义一个字符串String str = "蔡徐坤";//利用toCharArray() 方法将字符串转换为字符数组char[] charArray = str.toCharArray();System.out.println("string字符串一共有" + charArray.length + "个字符.");for (int i = 0; i < charArray.length; i++) {System.out.println("第" + (i + 1) + "个字符是:" + charArray[i]);}System.out.println("---------------------------------------");//利用charAt方法来直接获取字符串中的每一个字符元素char temp_char_0 = str.charAt(0);char temp_char_1 = str.charAt(1);char temp_char_2 = str.charAt(2);System.out.println("string字符串第一个元素为:" + temp_char_0);System.out.println("string字符串第二个元素为:" + temp_char_1);System.out.println("string字符串第三个元素为:" + temp_char_2);}
}

运行结果:

​4.1.2 基本类型 ——> String

基本类型转 String 最常见的两种方式:

① 直接与空字符串进行拼接

② String类的valueOf方法 

案例 

public class demo {public static void main(String[] args) {//方法一 : 以空字符串拼接的形式//byte --> Stringbyte temp_byte = 127;String temp_string_0 = 127 + "";//short --> Stringshort temp_short = 141;String temp_string_1 = temp_short + "";//int --> Stringint temp_int = 428;String temp_string_2 = temp_int + "";//long --> Stringlong temp_long = 11211;String temp_string_3 = temp_long + "";//float --> Stringfloat temp_float = 135.0F;String temp_string_4 = temp_float + "";//double --> Stringdouble temp_double = 433.0;String temp_string_5 = temp_double + "";//char --> Stringchar temp_char = 'A';String temp_string_6 = temp_char + "";//boolean --> Stringboolean temp_boolean = true;String temp_string_7 = temp_boolean + "";System.out.println("temp_string_0 = " + temp_string_0);System.out.println("temp_string_1 = " + temp_string_1);System.out.println("temp_string_2 = " + temp_string_2);System.out.println("temp_string_3 = " + temp_string_3);System.out.println("temp_string_4 = " + temp_string_4);System.out.println("temp_string_5 = " + temp_string_5);System.out.println("temp_string_6 = " + temp_string_6);System.out.println("temp_string_7 = " + temp_string_7);System.out.println("========================================");//方法二 : 利用String类的valueOf方法temp_string_0 = String.valueOf(temp_byte) + "_EX";temp_string_1 = String.valueOf(temp_short) + "_EX";temp_string_2 = String.valueOf(temp_int) + "_EX";temp_string_3 = String.valueOf(temp_long) + "_EX";temp_string_4 = String.valueOf(temp_float) + "_EX";temp_string_5 = String.valueOf(temp_double) + "_EX";temp_string_6 = String.valueOf(temp_char) + "_EX";temp_string_7 = String.valueOf(temp_boolean) + "_EX";System.out.println("temp_string_0 = " + temp_string_0);System.out.println("temp_string_1 = " + temp_string_1);System.out.println("temp_string_2 = " + temp_string_2);System.out.println("temp_string_3 = " + temp_string_3);System.out.println("temp_string_4 = " + temp_string_4);System.out.println("temp_string_5 = " + temp_string_5);System.out.println("temp_string_6 = " + temp_string_6);System.out.println("temp_string_7 = " + temp_string_7);}
}

4.2 String类型和包装类型的相互转化

4.2.1 String ——> 包装类

String 类转化为包装类有 2 种方式:

① 利用包装类的parseXXX例如:Integer integer_0 = Integer. parseInt(字符串类型变量);

② 利用包装类的构造器,例如 : Integer integer_1 = new Integer(字符串类型变量); 

补充:方式 ① 中用到了 parseInt 方法,而在上文 String 类型转基本类型时也用到了 parseInt 方法,但当时是用 int 类型变量来作接收的。先看一下 parseInt 的源码:

可以看到 parseInt 的返回值类型是 int 类型,因此方式 实际上应用了自动装箱,把等号右边返回的 int 类型的值,在底层又调用 valueOf 方法装箱成了 Integer 包装类

案例 

public class demo {public static void main(String[] args) {//演示 : String类型 ————> 包装类型//方式一String string_0 = "141";Integer integer_0 = Integer.parseInt(string_0);//方式二String string_1 = "133";Integer integer_1 = new Integer(string_1);System.out.println("integer_0的值 = " + integer_0);System.out.println("integer_1的值 = " + integer_1);}
}

4.2.2 包装类 ——> String

包装类转换为 String 类型有 3 种方式:

String xxx = 包装类变量名 + "";
String xxx = 包装类类名.toString();
String xxx = String.valueOf(...);

方式 和上文中提到的基本类型转 String 类型的方式是一回事

方式 体现出包装类相对于基本类型的优势,可以直接调用包装类中的方法

方式 ③ 使用的是 StringvalueOf 方法,valueOf 内部调用的就是包装类的 toString 方法,源码如下:

案例:Integer ——> String

public class demo{public static void main(String[] args){Integer integer_0 = 146;//自动装箱//包装类->String类的三种方式String str1 = integer_0 + "";//方式1String str2 = Integer.toString(integer_0);//方式2String str3 = String.valueOf(integer_0);//方式3System.out.println("str1 = " + str1);System.out.println("str2 = " + str2);System.out.println("str3 = " + str3);}
}

5.八大包装类的常用成员方法

每个包装类下的方法都很多,本文只讲一些比较常用的,遇到不懂的问问 GPT 或者 DeepSeek 就行了。查看其方法可以通过如下步骤:

​5.1 Byte类常用方法

byte byteValue() :返回当前 Byte 类对象对应的值,以 byte 类型作接收

② static int compare(byte x, byte y) :比较两个 byte 变量的值。返回值:前面 byte 变量的值减去后面 byte 变量的值

③ int compareTo(Byte anotherByte):比较两个 Byte 类对象的值,返回值同 

④ double doubleValue() :返回当前 Byte 类对象对应的值,以 double 类型作接收

int intValue():返回当前 Byte 类对象对应的值,以 int 类型作接收

⑥ static int parseByte(String xxx): 字符串类型 ——> byte 类型

String toString():将当前 Byte 对象的值转换为 String 类型

static String toString(byte b):将指定的 byte 值转换为 String 对象

static Byte valueOf(...):字符串类型 ——> Byte 类型

案例演示

public class demo {public static void main(String[] args) {//演示 : Byte类常用方法//1 —— byte byteValue() : 返回当前Byte类对象对应的值,以byte类型作接收Byte b = 127;   //自动装箱byte bb = b.byteValue();System.out.println("byte类型变量bb = " + bb);System.out.println("----------------------------------");//2 —— static int compare(byte x, byte y) : 比较两个byte变量的值, 返回值为前面byte变量的值减去后面byte变量的值byte temp_b_0 = 5;byte temp_b_1 = 1;int i = Byte.compare(temp_b_0, temp_b_1);System.out.println("temp_b_0 - temp_b_1 = " + i);System.out.println("----------------------------------");//3 —— int compareTo(Byte anotherByte) : 比较两个Byte类对象的值,返回值同方法2Byte temp_B_0 = 55;Byte temp_B_1 = 11;int i1 = temp_B_0.compareTo(temp_B_1);System.out.println("temp_B_0 - temp_B_1 = " + i1);System.out.println("----------------------------------");//4 —— double doubleValue() : 返回当前Byte类对象对应的值,以double类型作接收double bb1 = b.doubleValue();System.out.println("double类型变量bb1 = " + bb1);System.out.println("----------------------------------");//5 —— int intValue() : 返回当前Byte类对象对应的值,以int类型作接收int bb2 = b.intValue();System.out.println("int类型变量bb2 = " + bb2);System.out.println("----------------------------------");//6 —— static int parseByte(String xxx) : 字符串类型 ——> byte类型byte temp_b_2 = Byte.parseByte("1");System.out.println("byte类型变量temp_b_2 = " + temp_b_2);System.out.println("----------------------------------");//7 —— String toString() : 将当前Byte对象的值转换为String类型Byte temp_B_2 = 127;String string_0 = temp_B_2.toString();System.out.println("Byte类型对象temp_B_2的字符串形式为:" + string_0);System.out.println("----------------------------------");//8 —— static String toString(byte b) : 将指定的byte值转换为String对象byte temp_b_3 = 2;String string_1 = Byte.toString(temp_b_3);System.out.println("byte类型变量temp_b_3的字符串形式为:" + string_1);System.out.println("----------------------------------");//9 —— static Byte valueOf(...) : 字符串类型 ——> Byte类型Byte temp_B_3 = Byte.valueOf("11");System.out.println("Byte类型对象temp_B_3的值 = " + temp_B_3);}
}

5.2 Short类常用方法

① Short.MIN_VALUE、Short.MAX_VALUE:返回 Short/short 类型的最小值、最大值

② short shortValue():返回当前 Short 类对象对应的值,以 short 类型作接收

③ static int compare(short x, short y):比较两个 short 变量的值, 返回值:前面 short 变量的值减去后面 short 变量的值

④ int compareTo(Short anotherShort):比较两个 Short 类对象的值,返回值同

⑤ double doubleValue():返回当前 Short 类对象对应的值,以 double 类型作接收

⑥ int intValue():返回当前 Short 类对象对应的值,以 int 类型作接收

⑦ static int parseShort(String xxx) : 字符串类型 ——>  short 类型

⑧ String toString():将当前 Short 对象的值转换为 String 类型

⑨ static String toString(short s):将指定的 short 值转换为 String 对象

⑩ static Short valueOf(...):字符串类型 ——> Short 类型

案例演示

public class demo {public static void main(String[] args) {//演示Short类常用方法//1 —— Short.MIN_VALUE,Short.MAX_VALUE,返回Short/short类型的最小值、最大值System.out.println(Short.MIN_VALUE);System.out.println(Short.MAX_VALUE);System.out.println("------------------------------------");//2 —— short shortValue() : 返回当前Short对象的值,以short基本类型作接收Short temp_S_0 = 128;       //自动装箱short temp_s_0 = temp_S_0.shortValue();System.out.println("short类型变量temp_s_0 = " + temp_s_0);System.out.println("------------------------------------");//3 —— static int compare(short x, short y) : 比较两个short变量的值, 返回值为前面short变量的值减去后面short变量的值short temp_s_1 = 6;short temp_s_2 = 3;int i = Short.compare(temp_s_1, temp_s_2);System.out.println("temp_s_1 - temp_s_2 = " + i);System.out.println("------------------------------------");//4 —— int compareTo(Short anotherShort) : 比较两个Short类对象的值,返回值同3Short temp_S_1 = 66;Short temp_S_2 = 33;int i1 = temp_S_1.compareTo(temp_S_2);System.out.println("temp_S_1 - temp_S_2 = " + i1);System.out.println("------------------------------------");//5 —— double doubleValue() : 返回当前Short对象的值,以double基本类型作接收double temp_d_0 = temp_S_0.doubleValue();System.out.println("double类型变量temp_d_0 = " + temp_d_0);System.out.println("------------------------------------");//6 —— int intValue() : 返回当前Short对象的值,以int基本类型作接收int temp_i_0 = temp_S_0.intValue();System.out.println("int类型变量temp_i_0 = " + temp_i_0);System.out.println("------------------------------------");//7 —— static int parseShort(String xxx) : 字符串类型 ——> short基本类型short temp_s_3 = Short.parseShort("128");System.out.println("short类型变量temp_s_3 = " + temp_s_3);System.out.println("------------------------------------");//8 —— String toString() : 将当前Short对象的值转换为String类型Short temp_S_3 = 1277;String string_0 = temp_S_3.toString();System.out.println("Short类型对象temp_S_3的字符串形式为:" + string_0);System.out.println("------------------------------------");//9 —— static String toString(short s) : 将指定的short值转换为String对象short temp_s_4 = 2;String string_1 = Short.toString(temp_s_4);System.out.println("short类型变量temp_s_4的字符串形式为:" + string_1);System.out.println("----------------------------------");//10 —— static Short valueOf(...) : 字符串类型 ——> Short类型Short temp_S_4 = Short.valueOf("1111");System.out.println("Short类型对象temp_S_4的值 = " + temp_S_4);}
}

5.3 Integer类常用方法

① Integer.MIN_VALUE、Integer.MAX_VALUE:返回 Integer/int 类型的最小值、最大值

② int intValue() 、double doubleValue():返回当前 Integer 类对象对应的值,以 int/double 类型作接收

③ static int compare(int x, int y): 比较两个 int 变量的值。返回值:如果前一个数大,返回 1 ;如果前一个数小,返回 -1 ;相等则返回 0

④ int compareTo(Integer anotherInteger):比较两个 Integer 类对象的值,返回值同

⑤ static int parseInt(String xxx):字符串类型 ——>  int 类型

⑥ String toString(): 将当前 Integer 对象的值转换为 String 类型

⑦ static String toString(short s):将指定的 int 值转换为 String 对象

⑧ static Short valueOf(...):字符串类型 ——> Integer 类型

 static int max(int x, int y) 和 min(int x, int y):获取两个数中的最大值和最小值

static int sum(int x, int y):返回(x + y)的值

案例演示

public class demo {public static void main(String[] args) {//演示Integer类常用方法//1 —— Integer.MIN_VALUE,Integer.MAX_VALUE,返回Integer/int类型的最小值、最大值System.out.println(Integer.MIN_VALUE);System.out.println(Integer.MAX_VALUE);System.out.println("------------------------------------");//2 —— int intValue()、double doubleValue() : 返回当前Integer对象的值,以int/double基本类型作接收Integer temp_I_0 = 1280;       //自动装箱int temp_i_0 = temp_I_0.intValue();double temp_d_0 = temp_I_0.doubleValue();System.out.println("int类型变量temp_i_0 = " + temp_i_0);System.out.println("double类型变量temp_d_0 = " + temp_d_0);System.out.println("------------------------------------");//3 —— static int compare(int x, int y) : 比较两个int变量的值。如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0int temp_i_1 = 7;int temp_i_2 = 11;int i = Integer.compare(temp_i_1, temp_i_2);System.out.println("temp_i_1和temp_i_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i);System.out.println("------------------------------------");//4 —— int compareTo(Integer anotherInteger) : 比较两个Integer类对象的值,返回值同方法3Integer temp_I_1 = 77;Integer temp_I_2 = 11;int i1 = temp_I_1.compareTo(temp_I_2);System.out.println("temp_I_1和temp_I_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i1);System.out.println("------------------------------------");//5 —— static int parseInt(String xxx) : 字符串类型 ——> int基本类型int temp_i_3 = Integer.parseInt("4444");System.out.println("int类型变量temp_i_3 = " + temp_i_3);System.out.println("------------------------------------");//6 —— String toString() : 将当前Integer对象的值转换为String类型Integer temp_I_3 = 11217;String string_0 = temp_I_3.toString();System.out.println("Integer类型对象temp_I_3的字符串形式为:" + string_0);System.out.println("------------------------------------");//7 —— static String toString(int s) : 将指定的int值转换为String对象int temp_i_4 = 111111;String string_1 = Integer.toString(temp_i_4);System.out.println("int类型变量temp_i_4的字符串形式为:" + string_1);System.out.println("----------------------------------");//8 —— static Integer valueOf(...) : 字符串类型 ——> Integer类型Integer temp_I_4 = Integer.valueOf("1111");System.out.println("Integer类型对象temp_I_4的值 = " + temp_I_4);System.out.println("----------------------------------");//9 —— static int max(int x, int y) 和 min(int x, int y) : 获取两个数中的最大值和最小值System.out.println("100和101哪个数更大?" + Integer.max(100, 101));System.out.println("200和201哪个数更小?" + Integer.min(200, 201));System.out.println("----------------------------------");//10 —— static int sum(int x, int y) : 返回(x + y)的值System.out.println("100 + 201 = " + Integer.sum(100 ,201));}
}

5.4 Long类常用方法

① Long.MIN_VALUE、Long.MAX_VALUE:返回 Long/long 类型的最小值、最大值

② long longValue()、int intValue() 、double doubleValue():返回当前 Long 类对象对应的值,以 long/int/double 类型作接收

③ static int compare(long x, long y):比较两个 long 变量的值。返回值:如果前一个数大,返回 1 ;如果前一个数小,返回 -1 ;相等则返回 0

④ int compareTo(Long anotherLong):比较两个 Long 类对象的值,返回值同 

⑤ static long parseLong(String xxx):字符串类型 ——> long 类型

⑥ String toString():将当前 Long 对象的值转换为 String 类型

⑦ static String toString(long l):将指定的 long 值转换为 String 对象

⑧ static Long valueOf(...):字符串类型 ——> Long 类型

 static long max(long x, long y) 和 min(long x, long y):获取两个数中的最大值和最小值

static long sum(long x, long y):返回(x + y)的值

案例演示

public class demo {public static void main(String[] args) {//演示Long类常用方法//1 —— Long.MIN_VALUE,Long.MAX_VALUE,Long/long类型的最小值、最大值System.out.println(Long.MIN_VALUE);System.out.println(Long.MAX_VALUE);System.out.println("------------------------------------");//2 —— long longValue()、int intValue()、double doubleValue(): 返回当前Long对象的值,以long/int/double基本类型作接收Long temp_L_0 = 2224L;       //自动装箱long temp_l_0 = temp_L_0.longValue();int temp_i_0 = temp_L_0.intValue();double temp_d_0 = temp_L_0.doubleValue();System.out.println("long类型变量temp_l_0 = " + temp_l_0);System.out.println("int类型变量temp_i_0 = " + temp_i_0);System.out.println("double类型变量temp_d_0 = " + temp_d_0);System.out.println("------------------------------------");//3 —— static int compare(long x, long y) : 比较两个long变量的值. 如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0long temp_l_1 = 222L;long temp_l_2 = 111L;int i = Long.compare(temp_l_1, temp_l_2);System.out.println("temp_l_1和temp_l_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i);System.out.println("------------------------------------");//4 —— int compareTo(Long anotherLong) : 比较两个Long类对象的值,返回值同方法3Long temp_L_1 = 773L;Long temp_L_2 = 113L;int i1 = temp_L_1.compareTo(temp_L_2);System.out.println("temp_L_1和temp_L_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i1);System.out.println("------------------------------------");//5 —— static long parseLong(String xxx) : 字符串类型 ——> long基本类型long temp_l_3 = Long.parseLong("35252");System.out.println("long类型变量temp_l_3 = " + temp_l_3);System.out.println("------------------------------------");//6 —— String toString() : 将当前Long对象的值转换为String类型Long temp_L_3 = 11217L;String string_0 = temp_L_3.toString();System.out.println("Long类型对象temp_L_3的字符串形式为:" + string_0);System.out.println("------------------------------------");//7 —— static String toString(long l) : 将指定的long值转换为String对象long temp_l_4 = 222222;String string_1 = Long.toString(temp_l_4);System.out.println("long类型变量temp_l_4的字符串形式为:" + string_1);System.out.println("----------------------------------");//8 —— static Long valueOf(...) : 字符串类型 ——> Long类型Long temp_L_4 = Long.valueOf("111241");System.out.println("Long类型对象temp_L_4的值 = " + temp_L_4);System.out.println("----------------------------------");//9 —— static long max(long x, long y) 和 min(long x, long y) : 获取两个数中的最大值和最小值System.out.println("10000和10100哪个数更大?" + Long.max(10000, 10100));System.out.println("20000和20100哪个数更小?" + Long.min(20000, 20100));System.out.println("----------------------------------");//10 —— static long sum(long x, long y) : 返回(x + y)的值System.out.println("11111111 + 8888889 = " + Long.sum(11111111 ,8888889));}
}

5.5 Character类常用方法 

① char charValue():返回当前 Character 类对象对应的值,以 char 类型作接收

② static Character valueOf(...):字符串类型 ——> Character 类型

③ static int compare(char x, char y):比较两个 Character 类对象的字符。返回值: xASCII 码值 - yASCII 码值

④ int compareTo(Character anotherCharater):比较两个 Character 类对象的值,返回值同 

⑤  

(1)static boolean isDigit(char c1) : 判断该字符是不是数字
(2)static boolean isLetter(char c2) : 判断该字符是不是字母
(3)static boolean isUpperCase(char c3) : 判断该字符是不是大写形式
(4)static boolean isLowerCase(char c4) : 判断该字符是不是小写形式
(5)static boolean isWhitespace(char c5) : 判断该字符是不是空格

⑥ 

(1)static char toUpperCase(char c) : 将该字符转换为大写形式,以char类型作接收
(2)static char toLowerCase(char c) : 将该字符转换为小写形式,以char类型作接收

案例演示 

public class demo {public static void main(String[] args) {//演示 : Character类常用方法//1 —— char charValue():返回当前Character类对象对应的值,以char类型作接收Character character_0 = '蔡';//自动装箱char char_0 = character_0.charValue();System.out.println("char基本类型变量char_0 = " + char_0);System.out.println("----------------------------------");//2 ——  static Character valueOf(...) :字符串类型 ——> Character类型Character character_1 = Character.valueOf('S');System.out.println("Character类对象character_1的字符是:" + character_0);System.out.println("----------------------------------");//3 —— static int compare(char x, char y) : 返回前面字符ASCII码值 - 后面字符ASCII值的int类型int i1 = Character.compare('A', 'F');System.out.println("ASCII码值'A' - 'F' = " + i1);System.out.println("----------------------------------");//4 —— int compareTo(Character anotherCharacter) : 比较两个Character类对象的字符,返回值同方法2Character character_2 = 'a';Character character_3 = 'd';int i2 = character_2.compareTo(character_3);System.out.println("character_2 - character_3 = " + i2);System.out.println("----------------------------------");/*5—— static boolean isDigit(char c1) : 判断该字符是不是数字—— static boolean isLetter(char c2) : 判断该字符是不是字母—— static boolean isUpperCase(char c3) : 判断该字符是不是大写形式—— static boolean isLowerCase(char c4) : 判断该字符是不是小写形式—— static boolean isWhitespace(char c5) : 判断该字符是不是空格*/System.out.println("\'A\'是不是数字 : " + Character.isDigit('A'));System.out.println("\'A\'是不是字母 : " + Character.isLetter('A'));System.out.println("\'A\'是不是大写形式 : " + Character.isUpperCase('A'));System.out.println("\'A\'是不是小写形式 : " + Character.isLowerCase('A'));System.out.println("\'A\'是不是空格 : " + Character.isWhitespace('A'));System.out.println("----------------------------------");/*6—— static char toUpperCase(char c) : 将该字符转换为大写形式,以char类型作接收—— static char toLowerCase(char c) : 将该字符转换为小写形式,以char类型作接收*/char c1 = Character.toUpperCase('n');char c2 = Character.toLowerCase('B');System.out.println("\'n\'字符的大写形式为:" + c1);System.out.println("\'B\'字符的小写形式为:" + c2);}
}

5.6 Float类常用方法

① Float.MIN_VALUE、Float.MAX_VALUE:返回 Float/float 类型的最小值、最大值

② float floatValue()、int intValue() 、long doubleValue()、double doubleValue():返回当前 Float 类对象对应的值,以 float/int/long/double 类型作接收

③ static int compare(float x, float y):比较两个 float 变量的值。返回值:如果前一个数大,返回 1 ;如果前一个数小,返回 -1 ;相等则返回 0

④ int compareTo(Float anotherFloat):比较两个 Float 类对象的值,返回值同

⑤ static float parseFloat(String xxx):字符串类型 ——> float 类型

⑥ String toString():将当前 Float 对象的值转换为 String 类型

⑦ static String toString(float f):将指定的 float 值转换为 String 对象

⑧ static Float valueOf(...):字符串类型 ——> Float 类型

⑨ static float max(float x, float y) 和 min(float x, float y):获取两个数中的最大值和最小值

⑩ static float sum(float x, float y):返回(x + y)的值

案例演示 

public class demo {public static void main(String[] args) {//演示 : Float类常用方法//1 —— Float.MIN_VALUE,Float.MAX_VALUE,Float/float类型的最小值、最大值System.out.println(Float.MIN_VALUE);System.out.println(Float.MAX_VALUE);System.out.println("------------------------------------");//2 —— float floatValue()、int intValue()、long longValue()、double doubleValue: 返回当前Float对象的值,以float/int/long/double基本类型作接收。Float temp_F_0 = 1024.11F;//自动装箱float temp_f_0 = temp_F_0.floatValue();int temp_i_0 = temp_F_0.intValue();long temp_l_0 = temp_F_0.longValue();double temp_d_0 = temp_F_0.doubleValue();System.out.println("float类型变量temp_f_0 = " + temp_f_0);System.out.println("int类型变量temp_i_0 = " + temp_i_0);System.out.println("long类型变量temp_l_0 = " + temp_l_0);System.out.println("double类型变量temp_d_0 = " + temp_d_0);System.out.println("------------------------------------");//3 —— static int compare(float x, float y) : 比较两个float变量的值, 如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0float temp_f_1 = 222.11F;float temp_f_2 = 222.11F;int i = Float.compare(temp_f_1, temp_f_2);System.out.println("temp_f_1和temp_f_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i);System.out.println("------------------------------------");//4 —— int compareTo(Float anotherFloat) : 比较两个Float类对象的值,返回值同方法3Float temp_F_1 = 222.11F;Float temp_F_2 = 123.11F;int i1 = temp_F_1.compareTo(temp_F_2);System.out.println("temp_F_1和temp_F_2,如果前一个数大,返回1;如果前一个数小,返回-1;相等则返回0 : " + i1);System.out.println("------------------------------------");//5 —— static float parseFloat(String xxx) : 字符串类型 ——> float基本类型float temp_f_3 = Float.parseFloat("35252.11125");System.out.println("float类型变量temp_f_3 = " + temp_f_3);System.out.println("------------------------------------");//6 —— String toString() : 将当前Float对象的值转换为String类型Float temp_F_3 = 12144217.12F;String string_0 = temp_F_3.toString();System.out.println("Float类型对象temp_F_3的字符串形式为:" + string_0);System.out.println("------------------------------------");//7 —— static String toString(float f) : 将指定的float值转换为String对象float temp_f_4 = 222222.11F;String string_1 = Float.toString(temp_f_4);System.out.println("float类型变量temp_f_4的字符串形式为:" + string_1);System.out.println("----------------------------------");//8 —— static Float valueOf(...) : 字符串类型 ——> Float类型Float temp_F_4 = Float.valueOf("111241.1235");System.out.println("Float类型对象temp_F_4的值 = " + temp_F_4);System.out.println("----------------------------------");//9 —— static float max(float x, float y) 和 min(float x, float y) : 获取两个数中的最大值和最小值System.out.println("10000.00 和 10100.11, 哪个数更大?" + Float.max(10000.00F, 10100.11F));System.out.println("200.00 和 201.88, 哪个数更小?" + Float.min(200.00F, 201.88F));System.out.println("----------------------------------");//10 —— static float sum(float x, float y) : 返回(x + y)的值System.out.println("11111.11 + 8889.022 = " + Float.sum(11111.11F,8889.022F));}
}

5.7 Double类常用方法

Float 类完全一致,这里不再赘述

5.8 Boolean类常用方法

① boolean booleanValue():返回当前 Boolean 类对象对应的值,以 boolean 类型作接收

② static int compare(boolean x,boolean y):比较两个 boolean 变量的值,两个变量真值相同返回 0 .否则返回值取决于于第一个 boolean 变量的真值,true 返回 1false 返回 -1

③ int compareTo(Boolean anotherBoolean):比较两个 Boolean 类对象的值,返回值同

④ static boolean parseBoolean(String xxx):字符串类型 ——>  boolean 类型

⑤ String toString():将当前 Boolean 对象的值转换为 String 类型

⑥ static String toString(boolean b):将指定的 boolean 值转换为 String 对象

⑦ static Boolean valueOf(...) :字符串类型 ——> Boolean 类型

 案例演示

public class demo {public static void main(String[] args) {//演示 : Boolean类常用方法//1 —— boolean booleanValue():返回当前Boolean类对象对应的值,以boolean类型作接收Boolean temp_B_0 = true;//自动装箱boolean temp_b_0 = temp_B_0.booleanValue();System.out.println("boolean类型变量temp_b_0 = " + temp_b_0);System.out.println("------------------------------------");//2 —— static int compare(boolean x, boolean y) : 比较两个boolean变量的值,两个变量真值相同返回0。否则返回值取决于第一个boolean变量的真值,true返回1,false返回-1.boolean temp_b_1 = false;boolean temp_b_2 = true;int i = Boolean.compare(temp_b_1, temp_b_2);int ii = Boolean.compare(temp_b_2, temp_b_1);int iii = Boolean.compare(temp_b_2, temp_b_2);System.out.println("temp_b_1和temp_b_2, 两个真值相同返回1。否则返回值取决于传入第一个boolean变量的真值,true返回1,false返回-1 : " + i);System.out.println("temp_b_2和temp_b_1, 两个真值相同返回1。否则返回值取决于传入第一个boolean变量的真值,true返回1,false返回-1 : " + ii);System.out.println("temp_b_2和temp_b_2, 两个真值相同返回1。否则返回值取决于传入第一个boolean变量的真值,true返回1,false返回-1 : " + iii);System.out.println("------------------------------------");//3 —— int compareTo(Boolean anotherBoolean) : 比较两个Boolean类对象的值,返回值同方法2Boolean temp_B_1 = false;Boolean temp_B_2 = false;int i1 = temp_B_1.compareTo(temp_B_2);System.out.println("temp_B_1和temp_B_2的真值情况是 : " + i1);System.out.println("------------------------------------");//4 —— static boolean parseBoolean(String xxx) : 字符串类型 ——> boolean基本类型boolean temp_b_3 = Boolean.parseBoolean("666");System.out.println("boolean类型变量temp_b_3 = " + temp_b_3);System.out.println("------------------------------------");//5 —— String toString() : 将当前Boolean对象的值转换为String类型Boolean temp_B_3 = false;String string_0 = temp_B_3.toString();System.out.println("Boolean类型对象temp_B_3的字符串形式为:" + string_0);System.out.println("------------------------------------");//6 —— static String toString(boolean s) : 将指定的boolean值转换为String对象boolean temp_b_4 = true;String string_1 = Boolean.toString(temp_b_4);System.out.println("boolean类型变量temp_b_4的字符串形式为:" + string_1);System.out.println("----------------------------------");//7 —— static Boolean valueOf(...) : 字符串类型 ——> Boolean类型Boolean temp_B_4 = Boolean.valueOf("false");System.out.println("Boolean类型对象temp_B_4的值 = " + temp_B_4);}
}

6.Integer创建机制的面试题(重要)

 Integer.valueOf 的源码在本文的 3.3自动拆装箱 已经提到,这里不作赘述

② 基本数据类型与其对应的包装类用 "==" 比较时,比较的是值是否相等

6.1 练习题1

判断输出结果

public class demo{public static void main(String[] args){Integer i = new Integer(1);Integer j = new Integer(1);System.out.println(i==j);//false,i与j是两个不同的对象Integer m = 1;//自动装箱,底层调用的是Integer.valueOf(1),从缓冲数组cache中取IntegerInteger n = 1;//自动装箱,底层调用的是Integer.valueOf(1),从缓冲数组cache中取IntegerSystem.out.println(m==n);//trueInteger x = 128;//自动装箱,底层调用的是Integer.valueOf(128),new一个新的IntegerInteger y = 128;//自动装箱,底层调用的是Integer.valueOf(128),new一个新的IntegerSystem.out.println(x==y);//false}
}

6.2 练习题2

判断输出结果

public class demo{public static void main(String[] args){Integer i1 = 127;//自动装箱,底层调用的是Integer.valueOf(127),从缓冲数组cache中取IntegerInteger i2 = new Integer(127);//new一个新的IntegerSystem.out.println(i1==i2);//falseInteger i3 = 127;//自动装箱,底层调用的是Integer.valueOf(127),从缓冲数组cache中取Integerint i4 = 127;System.out.println(i3==i4);//true,判断的是值是否相等Integer i5 = 128;//自动装箱,底层调用的是Integer.valueOf(128),new一个新的Integerint i6 = 128;System.out.println(i5==i6);//true,判断的是值是否相等}
}

相关文章:

【Java SE】包装类 Byte、Short、Integer、Long、Character、Float、Double、Boolean

参考笔记&#xff1a;java 包装类 万字详解&#xff08;通俗易懂)_java包装类-CSDN博客 目录 1.简介 2.包装类的继承关系图 3.装箱和拆箱 3.1 介绍 3.2 手动拆装箱 3.3. 自动拆装箱 ​4.关于String类型的转化问题 4.1 String类型和基本类型的相互转化 4.1.1 String —…...

口腔种植全流程AI导航系统及辅助诊疗与耗材智能化编程分析

一、系统架构与编程框架设计 口腔种植全流程人工智能导航系统的开发是一项高度复杂的多学科融合工程,其核心架构需在医学精准性、工程实时性与临床实用性之间实现平衡。系统设计以模块化分层架构为基础,结合高实时性数据流与多模态协同控制理念,覆盖从数据采集、智能决策到…...

小林coding-10道Java集合面试题

1.数组与集合区别&#xff0c;用过哪些&#xff1f;说说Java中的集合&#xff1f;Java中的线程安全的集合是什么&#xff1f;Collections和Collection的区别?集合遍历的方法有哪些&#xff1f; 2.List?讲一下java里面list的几种实现&#xff0c;几种实现有什么不同&#xff…...

Java 集合中ArrayList与LinkedList的性能比较

一、需求&#xff1a; 头部插入‌&#xff1a;向列表头部插入10万个整数。‌随机访问‌&#xff1a;从列表中间位置连续获取1万个元素。‌头部删除‌&#xff1a;从列表头部连续删除10万个元素。 二、 使用ArrayList与LinkedList测试 //常量定义&#xff0c;用于测试操作的次数…...

SQL问题分析与诊断(8)——前提

8.1. 前提 与其他关系库类似&#xff0c;SQL Server中&#xff0c;当我们对存在性能问题的SQL语句进行分析和诊断时&#xff0c;除了获取该SQL语句本身外&#xff0c;还需要获取SQL语句相应的查询计划及其相关的数据环境。这里&#xff0c;所谓数据环境&#xff0c;具体是指SQ…...

漏洞发现:AWVS 联动 XRAY 图形化工具.(主动+被动 双重扫描)

漏洞发现&#xff1a;AWVS 联动 XRAY 图形化工具. 漏洞发现是网络安全领域的关键环节&#xff0c;指通过技术手段识别计算机系统、网络设备或软件中存在的设计缺陷、配置错误或代码漏洞的过程。这些漏洞可能被攻击者利用&#xff0c;导致数据泄露、服务中断或权限提升等风险。…...

上门家政小程序实战,从0到1解决方案

一、逻辑分析 上门家政小程序主要涉及用户端和服务端两大部分。用户端需要实现服务浏览、预约下单、订单跟踪等功能&#xff1b;服务端则要处理订单管理、服务人员管理、数据统计等任务。以下是详细的功能模块分析&#xff1a; 用户注册与登录&#xff1a;用户通过手机号或第三…...

Linux ping/telnet/nc命令

在Linux操作系统中&#xff0c;ping命令用于测试网络连接和发送数据包到目的主机。 然而&#xff0c;ping命令默认情况下只能测试IP地址和域名&#xff0c;而无法直接测试端口号。 ping www.baidu.comping 192.168.0.1 测试端口 如果你想测试特定端口是否开放并响应&#xff…...

Netty - 从Nginx 四层(TCP/UDP)流量中获取客户端真实/网络出口IP

文章目录 一、背景与原理1.1 问题场景网络架构影响分析1.1 客户端与Nginx之间存在的NAT/VPN1.2 Nginx与RPC服务之间的NAT 1.2 技术原理 二、环境配置验证2.1 Nginx配置2.2 版本要求 三、Netty服务端实现3.1 Pipeline配置&#xff08;核心代码&#xff09;3.2 协议处理器实现3.3…...

【持续集成和持续部署】

大致流程&#xff1a; 提交代码--拉取下来新代码并自动构建与部署--应用接口探活--执行自动化测试--输出自动化测试报告 一、持续集成&#xff08;Continuous Integration&#xff0c;CI&#xff09; 持续集成是一种软件开发实践&#xff0c;开发团队成员频繁地将代码集成到…...

Transformers中的BertConfig、BertModel详解

目录 一、功能 二、用法 1.导入BertConfig 2. 初始化默认配置 3.使用配置初始化模型 使用场景&#xff1a; 1.自定义小型BERT模型 2.加载预训练模型配置 从 Hugging Face 模型库加载 bert-base-uncased 的默认配置&#xff1a; 通过 BertConfig&#xff0c;你可以灵活定义…...

Ubuntu下载docker、xshell

配置&#xff1a;VMware虚拟机、Ubuntu24.04.1 首先打开vm启动虚拟机 下载docker Ubuntu启动之后&#xff0c;按CTRLALTT 打开终端 1.更新软件包索引并安装依赖 sudo apt-get updatesudo apt-get install \ca-certificates \curl \gnupg \lsb-release 2.添加docker官方的GP…...

迅为iTOP-RK3576人工智能开发板Android 系统接口功能测试

2.1 开机启动 开发板接通电源&#xff0c;并按下电源开关&#xff0c;系统即启动&#xff0c;在启动过程中&#xff0c;系统会显示下图中的开机画面&#xff0c;它们分别是 Android 系统启动时的 Logo 画面&#xff1a; 最后会显示如下解锁画面&#xff1a; 2.2 命令终端 将…...

Android设计模式之工厂方法模式

一、定义&#xff1a; 定义一个用于创建对象的接口&#xff0c;让子类决定实例化哪个类。 二、组成&#xff1a; 1.抽象工厂&#xff1a;工厂模式的核心&#xff0c;声明工厂方法&#xff0c;返回抽象产品对象。 2.具体工厂&#xff1a;实现工厂方法&#xff0c;返还具体的产品…...

端侧设备(如路由器、家庭网关、边缘计算盒子、工业网关等)的典型系统、硬件配置和内存大小

🏠 家用/工业级边缘设备硬件概览 类型常见设备示例CPU 架构内存范围操作系统类型家用路由器TP-Link、小米、华硕、OpenWrtARM Cortex-A7/A964MB~256MBOpenWrt / DD-WRT / Embedded Linux智能家庭网关华为、绿米、天猫精灵、Aqara HubARM Cortex-M/R128MB~512MBEmbedded Lin…...

office_word中使用宏以及DeepSeek

前言 Word中可以利用DeepSeek来生成各种宏&#xff0c;从而生成我们需要各种数据和图表&#xff0c;这样可以大大减少我们手工的操作。 1、Office的版本 采用的是微软的office2016&#xff0c;如下图&#xff1a; 2、新建一个Word文档 3、开启开发工具 这样菜单中的“开发工具…...

数据结构day04

一 栈 1栈的基本概念 各位同学大家好&#xff0c;从这个小节开始&#xff0c;我们会正式进入第三章的学习&#xff0c;我们会学习栈和队列&#xff0c;那这个小节中我们会先认识栈的基本概念。我们会从栈的定义和栈的基本操作来认识栈这种数据结构&#xff0c;也就是要探讨栈的…...

质量工程:数字化转型时代的质量体系重构

前言&#xff1a;质量理念的范式转移阅读原文 如果把软件开发比作建造摩天大楼&#xff1a; 传统测试 竣工后检查裂缝&#xff08;高成本返工&#xff09; 质量工程 从地基开始的全流程监理体系&#xff08;设计图纸→施工工艺→建材选择→竣工验收&#xff09; IEEE研究…...

数据结构C语言练习(单双链表)

本篇练习题(单链表)&#xff1a; 1.力扣 203. 移除链表元素 2.力扣 206. 反转链表 3.力扣 876. 链表的中间结点 4.力扣 21. 合并两个有序链表 5. 牛客 链表分割算法详解 6.牛客 链表回文结构判断 7. 力扣 160. 相交链表 8. 力扣 141 环形链表 9. 力扣 142 环形链表 II…...

QScreen 捕获屏幕(截图)

一、QScreen核心能力解析 硬件信息获取 // 获取主屏幕对象 QScreen* primaryScreen QGuiApplication::primaryScreen();// 输出屏幕参数 qDebug() << "分辨率:" << primaryScreen->size(); qDebug() << "物理尺寸:" << primar…...

pyQt学习笔记——Qt资源文件(.qrc)的创建与使用

Qt资源文件&#xff08;.qrc&#xff09;的创建与使用 1. 选择打开资源2. 创建新资源3. 添加资源文件夹4. 选择要加载的图片文件5. 编译resource.qrc文件6. 替换PySlide6为PyQt57. 其他说明 1. 选择打开资源 在Qt项目中&#xff0c;可以通过windowIcon点击选择打开资源。 2. 创…...

优雅的开始一个Python项目

优雅的开始一个Python项目 这是我在初始化一个Python项目时&#xff0c;一键生成的项目文件。它自动完成了git初始化、环境管理、日志模块这三件事情&#xff0c;并在最后进入了虚拟环境。 uv安装 uv是一个现代的Python包管理和项目管理工具。uv中文文档 安装uv: # unix: …...

[学成在线]07-视频转码

视频转码 视频上传成功后需要对视频进行转码处理。 首先我们要分清文件格式和编码格式&#xff1a; 文件格式&#xff1a;是指.mp4、.avi、.rmvb等这些不同扩展名的视频文件的文件格式 &#xff0c;视频文件的内容主要包括视频和音频&#xff0c;其文件格式是按照一定的编码…...

qt+opengl 加载三维obj文件

1前面我们已经熟悉了opengl自定义顶点生成一个立方体&#xff0c;并且我们实现了立方体的旋转&#xff0c;光照等功能。下面我们来用opengl来加载一个obj文件。准备我们首先准备一个简单的obj文件&#xff08;head.obj&#xff09;。资源在本页下载 2 在obj文件里面&#xff0c…...

一个简单的用C#实现的分布式雪花ID算法

雪花ID是一个依赖时间戳根据算法生成的一个Int64的数字ID&#xff0c;一般用来做主键或者订单号等。以下是一个用C#写的雪花ID的简单实现方法 using System; using System.Collections.Concurrent; using System.Diagnostics;public class SnowflakeIdGenerator {// 配置常量p…...

【实战ES】实战 Elasticsearch:快速上手与深度实践-2.2.1 Bulk API的正确使用与错误处理

&#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 文章大纲 Elasticsearch Bulk API 深度实践&#xff1a;性能调优与容错设计1. Bulk API 核心机制解析1.1 批量写入原理剖析1.1.1 各阶段性能瓶颈 2. 高性能批量写入实践2.1 客户端最佳…...

鸿蒙Flutter开发故事:不,你不需要鸿蒙化

在华为牵头下&#xff0c;Flutter 鸿蒙化如火如荼进行&#xff0c;当第一次看到一份上百个插件的Excel 列表时&#xff0c;我也感到震惊&#xff0c;排名前 100 的插件赫然在列&#xff0c;这无疑是一次大规模的军团作战。 然后&#xff0c;参战团队鱼龙混杂&#xff0c;难免有…...

中间件框架漏洞攻略

中间件&#xff08;英语&#xff1a;Middleware&#xff09;是提供系统软件和应⽤软件之间连接的软件&#xff0c;以便于软件各部件之间的沟通。 中间件处在操作系统和更⾼⼀级应⽤程序之间。他充当的功能是&#xff1a;将应⽤程序运⾏环境与操作系统隔离&#xff0c;从⽽实…...

第21周:RestNet-50算法实践

目录 前言 理论知识 1.CNN算法发展 2.-残差网络的由来 一、导入数据 二、数据处理 四、编译 五、模型评估 六、总结 前言 &#x1f368; 本文为&#x1f517;365天深度学习训练营中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 理论知识 1.CNN算法发展 该图列举出…...

构建大语言模型应用:数据准备(第二部分)

本专栏通过检索增强生成&#xff08;RAG&#xff09;应用的视角来学习大语言模型&#xff08;LLM&#xff09;。 本系列文章 简介数据准备&#xff08;本文&#xff09;句子转换器向量数据库搜索与检索大语言模型开源检索增强生成评估大语言模型服务高级检索增强生成 RAG 如上…...