当前位置:网站首页>Day_ fourteen
Day_ fourteen
2022-06-25 16:25:00 【grp_ grp_ grp】
1. String
1.1 summary
java.lang.String : It's a string class , The bottom floor is a final Embellished char Array , therefore String Many features are the properties of arrays , For example, once the length is determined, it cannot be changed
1. Once the string is created , This string object cannot be changed
2. To improve string access and storage efficiency ,Java Virtual machines are a buffering mechanism , Save all strings to string constants
3. In the course of executing the program , A string is used to add a ,String s1 ="a" ; First, search the string constant , Is there a a, If not, create one
4. If there is , String s2 = "a"; No more creation , Take the existing one a return , So lead to String s1 ="a"; String s2 ="a"; here , Use s1==s2, He is also true, Because they point to the same string object Namely a
1.2 Basic use
The first part : Create an object , Because they all point to constant pools
The second part : If used new The way , Then the heap memory object will be created , The string object is stored in heap memory
1.3 Construction method
1.4 Common methods
Study API : ① What is the function ② What are input and output parameters ③ How to use it?
1 char charAt (int index ) : Returns... In the string , The character in the specified position
2 boolean endsWith(String suffix) : Determines whether the string ends with the specified string
boolean startsWith(String prefix) : Determine whether the string starts with the specified string
3 boolean equalsIgnoreCase(String str) : Case insensitive comparison of two strings for equality
4 byte[] getBytes() : Converts a string to a byte array and returns
5 char[] toCharArray() : Converts a string to a character array and returns
6 int indexOf(String str) : Gets the starting index of the specified string in the string , No return found -1
7 int indexOf(String str,int index) : Start at the specified location ( contain ), Gets the starting index of the specified string in the string , No return found -1
8 index lastIndexOf(String str) : ditto , The last index to appear No return found -1
9 int length() : Returns the length of the string
10 String replaceAll(String regex . String replacement); Replace specified characters , regular expression
String replace (String str . String replacement); Regular expressions are not supported
11 String[] split(String regex) : Split string , Return string array , regular expression , Be careful spot , Need to escape
12 String substring(int begin); In the string , Substring starting with a subscript ( contain )
13 String substring(int begin, int end) : In the string , Start with a subscript ( contain ) Substring ending at a subscript ( It doesn't contain )
14 String trim() : Remove the spaces on both sides of the string
15 String toUpperCase() : Turn capitalization
String toLowerCase() : Turn lowercase
16 static String valueOf(Object obj) : Calling the toString Method , If null, No more calls toString Instead, it returns a string null, When printing a reference type , Automatically called String Of valueOf therefore Automatically called toString Method
1.5 Be careful
2. StringBuffer and StringBuilder
2.1 summary
StringBuffer and StringBuilder: Are all string buffers , It can be used for splicing
StringBuffer、StringBuilder and String The difference between :
String : The bottom is char Array , Fixed length , Once determined, it cannot be changed , Not suitable for string splicing
StringBuffer and StringBuilder : The bottom is char Array , Lengthening , Apply for a piece of space in memory in advance , Used to save many characters if the reserved space is insufficient , It will automatically expand . Default capacity is 16, Expand capacity ( Current capacity +1)*2 16->34->70
StringBuilder and StringBuffer The difference between :
StringBuffer Thread safety , In multithreaded environment , No problem
StringBuilder Non-thread safety , Problems may occur in a multithreaded environment
2.2 Use
3. Packaging
3.1 summary
1. Boxing is the automatic conversion of basic data types to wrapper types
2. Unpacking is automatically converting the wrapper type to the basic data type
3.2 Use
Basic types byte b1=12
Encapsulate as wrapper class Byte b2=new Byte(b1);
3.3 Integer
3.4 transformation
3.5 summary
4. System
System Class provides the public static long currentTimeMillis() Used to return the current time Between and 1970 year 1 month 1 Japan 0 when 0 branch 0 The time difference in milliseconds between seconds
This method is suitable for calculating time difference .
System Class represents system , Many system level properties and control methods are placed inside the class . This class is located in java.lang package
Because the constructor of this class is private Of , So we can't create objects of this class , That is, it can't be realized Instantiate this class . Its internal member variables and member methods are static Of , So it can also be very convenient To call .
Common methods :
5. Date
5.1 summary
Get time and time operations
5.2 usage

6. Random
Use
边栏推荐
- Xinlou: un voyage de sept ans de Huawei Sports Health
- Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
- 普通人的2022春招总结(阿里、腾讯offer)
- Rxjs TakeUntil 操作符的学习笔记
- Introduction to database transactions
- Golang open source streaming media audio and video network transmission service -lal
- Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
- 10款超牛Vim插件,爱不释手了
- In the wechat environment, H5 jumps to the specified page of the applet
- Uncover gaussdb (for redis): comprehensive comparison of CODIS
猜你喜欢
Overall MySQL architecture and statement execution process
心樓:華為運動健康的七年築造之旅
数字经济时代文化消费新特征
Alvaria宣布客户体验行业资深人士Jeff Cotten担任新首席执行官
Record learning of hystrix knowledge --20210929
揭秘GaussDB(for Redis):全面对比Codis
Rxjs TakeUntil 操作符的学习笔记
Mixed density network (MDN) for multiple regression explanation and code example
Helsinki traffic safety improvement project deploys velodyne lidar Intelligent Infrastructure Solution
In the wechat environment, H5 jumps to the specified page of the applet
随机推荐
_ 17 collection overview
Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
GridLayout evenly allocate space
flutter
Uncover gaussdb (for redis): comprehensive comparison of CODIS
What are some tricks that novice programmers don't know?
[untitled]
Introduction to MgO 256gb NAND flash chip
Unity技术手册 - 生命周期内大小(Size over Lifetime)和速度决定大小(Size by Speed)
[Third Party framework] retrofit2 (1) of network request framework -- Getting Started Guide
Tensorflow loading cifar10 dataset
Converting cifar10 datasets
Webgl and webgpu comparison [4] - uniform
Rxjs TakeUntil 操作符的学习笔记
The textfield is encapsulated by the flutter itself, which causes the data display to be disordered when the data in the list is updated.
Div element
AutoK3s v0.5.0 发布 延续简约和友好
Learning notes of rxjs takeuntil operator
Precautions for function default parameters (formal parameter angle)
In the wechat environment, H5 jumps to the specified page of the applet