当前位置:网站首页>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

边栏推荐
- Load local cifar10 dataset
- The textfield is encapsulated by the flutter itself, which causes the data display to be disordered when the data in the list is updated.
- The style of the mall can also change a lot. DIY can learn about it!
- error Parsing error: Unexpected reserved word ‘await‘.
- Built in function globals() locals()
- Several ways of SQL optimization
- Deadlock, thread communication, singleton mode
- Message format of Modbus (PLC)
- Educational administration system development (php+mysql)
- 【机器学习】基于多元时间序列对高考预测分析案例
猜你喜欢

Unity技术手册 - 干扰/噪音/杂波(Noise)子模块

Alvaria announces Jeff cotten, a veteran of the customer experience industry, as its new CEO

Geographic location data storage scheme - redis Geo

Unity技术手册 - 生命周期内大小(Size over Lifetime)和速度决定大小(Size by Speed)

Bypass technology to talk about 'cross end'

深入理解和把握数字经济的基本特征

Prototype chain analysis

不要小看了积分商城,它的作用可以很大!

error Parsing error: Unexpected reserved word ‘await‘.

In the wechat environment, H5 jumps to the specified page of the applet
随机推荐
Alvaria announces Jeff cotten, a veteran of the customer experience industry, as its new CEO
Problems caused by using ApplicationContext to render layout
Most commonly used SQL statements
数据存储和传输文件之XML使用和解析详解
User registration, information writing to file
10 Super VIM plug-ins, I can't put them down
JS add custom attributes to elements
Advanced SQL statement 1 of Linux MySQL database
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
Preliminary understanding of JVM
Built in function globals() locals()
Understand the execution sequence of try catch finally in one diagram
_ 19_ IO stream summary
_ 17 collection overview
Analysis of the concept of metacosmic system
What are some tricks that novice programmers don't know?
Sleep formula: how to cure bad sleep?
Dart syntax
Uniapp converts graphic verification codes in the form of file streams into images