当前位置:网站首页>Small knowledge of common classes
Small knowledge of common classes
2022-07-25 10:16:00 【Look at the bugs】
Boxing and UnBoxing
Boxing turns basic types into reference types
Unpacking changes the reference type to the basic type
int age=30;
// Automatic boxing
Integer integer4=age;
// Automatic dismantling
int age2 =integer4;
Basic type and string conversion
//1, The basic type is converted to a string
int n1=10;
String n2= n1+"";
// Use Integer Medium toString() Method
String s2=Integer.toString(n1);
//toString Overload method of n1 With 16 Hexadecimal said
String s3=Integer.toString(n1,16);
//2, String to base type
String s1="yan";
// Use integer2.parseInt() Method put int The type changes to String type
int n3=integer2.parseInt(s1);
//boolean The string form is changed to the basic type :"true"-->true, Not true-->false
String str2="true";
boolean bl=Boolean.parseBoolean(str2);
== and equals
== When comparing two basic types , Compare values
The comparison is that the reference type is , The comparison is the address
equals stay Object Class compares addresses
String Class overridden equals Method , stay String Next equals Compare values
Integer buffer
//Integer The number stored in the buffer is -128 To 127 The array between is stored in the heap
// Recreate storage space beyond the scope
Integer integer1=Integer.valueOf(100);
Integer integer2=Integer.valueOf(100);
System.out.println(integer1==integer2);
//true
Integer integer6=new Integer(200);
Integer integer7=new Integer(200);
System.out.println(integer6==integer7);
//false
String Method
String content =" kankanshijie ";
System.out.println(content.length()); // Returns the length of the string
System.out.println(content.charAt(0)); // Get the current character according to the subscript
System.out.println(content.contains("iji")); // Determine if the string contains "" String inside
System.out.println(Arrays.toString(content.toCharArray()));
//content.toCharArray() The address of the current string is printed
//Arrays.toString Print the string of the current address
System.out.println(content.trim()); // Remove the space before and after the string
System.out.println(content.toUpperCase()); // Become capital
System.out.println(content.toLowerCase());// Become lowercase
System.out.println(content.replace("kank","wod"));
// Replace the specified string with the desired string
System.out.println(Arrays.toString(content.split("ka")));
// Split string
String say="java is the best programing ,My Language";
String []arr=say.split("[, ]+"); // Inside the brackets is the judgment of what to split. Here are spaces and commas
System.out.println(arr.length); // Print array length
for(String string:arr){
System.out.println(string); // Print the string in the array
}
// Compare the position of two strings in the table and subtract , From the first , If the same, compare the next
// If the two preceding characters are the same , Just compare the length of two strings
// Can be used for sorting
String s1="abc";
String s2="xyz";
System.out.println(s1.compareTo(s2));
边栏推荐
猜你喜欢
随机推荐
语音自监督预训练模型 CNN Encoder 调研总结
oracle 解析同名xml 问题
framework打包合并脚本
SSM整合(简单的图书管理系统来整合SSM)
Swing组件
Detailed explanation of MySQL database
Exception handling exception
严重 [main] org.apache.catalina.util.LifecycleBase.handleSubClassException 初始化组件
Nodejs initial experience
字符串最长公共前缀
Common methods of JS digital thousand bit segmentation
Redis和MongoDB的区别
Dataset 和 Dataloader数据加载
复现 ASVspoof 2021 baseline RawNet2
四舍五入取近似值
struct2的原理
File upload function
Trojaning Attack on Neural Networks 论文阅读笔记
vant问题记录
关于slf4j log4j log4j2的jar包配合使用的那些事









