当前位置:网站首页>Common APIs
Common APIs
2022-07-03 07:06:00 【L gold p】
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 Can't change
Once the string is created , This string object cannot be changed
To improve string access and storage efficiency Java The virtual machine uses a caching mechanism , Save the strings to the string constant pool
In the process of execution , If you want to use a string a,String s1="a" First, search the character constant pool Is there a a, If not, create one If there is Sting s2="a"; No more creation , Take the existing one a return
So lead to String s1="a" String s2="a" here s1==s2 He is also true Because they point to the same string object Namely a

1、2 Basic use

1、3 Do not splice frequently


1、4 Construction method


1、5 Common methods
Study API
1 What is the function
2 What are input and output parameters
3 How to use it?
// 1 char charAt (int index ) : Returns... In the string , The character in the specified position
String s1 = "qwehihasd";
char c1 = s1.charAt(2);
// e
System.out.println(c1);
// 2 boolean endsWith(String suffix) : Determines whether the string ends with the specified string
// boolean startsWith(String prefix) : ditto , Judgment begins
System.out.println("Hello.java".endsWith(".java"));
// Note blank space , If there is a space, it won't match
System.out.println("Hello.java".endsWith(".java "));
// 3 boolean equalsIgnoreCase(String str) : Case insensitive comparison of two strings for equality
System.out.println("abc".equalsIgnoreCase("aBc"));
// 4 byte[] getBytes() : Converts a string to a byte array and returns
byte[] bytes = "abc".getBytes();
for (int i = 0; i < bytes.length; i++) {
System.out.println(bytes[i]);
}
// 5 char[] toCharArray() : Converts a string to a character array and returns
char[] chars = "abc".toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.println(chars[i]);
}
// 6 int indexOf(String str) : Gets the starting index of the specified string in the string , No return found -1
System.out.println("askdhqwbe".indexOf("kd")); // 2
System.out.println("askdhqwbe".indexOf("kda")); // -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
System.out.println("askdhaqwbe".indexOf("a", 5)); // -1
// 8 index lastIndexOf(String str) : ditto , The last index to appear No return found -1
System.out.println("askdhaqwbe".lastIndexOf("a")); // 5
// 9 int length() : Returns the length of the string
System.out.println("abc".length());
// 10 String replaceAll(String regex . String replacement);
// Replace specified characters , regular expression
// String replace (String str . String replacement); Regular expressions are not supported
// use 1 hold a Replaced and returned a new string
// regular expression , But I didn't write regular expressions There is no difference
System.out.println("hucgasdqweasd".replaceAll("a", "1"));
System.out.println("hucgasdqweasd".replace("a", "1"));
// because . In regular expressions , Arbitrary character
System.out.println("qwe.rty.yui.uio".replaceAll(".", ","));
// have access to \ escape
System.out.println("qwe.rty.yui.uio".replaceAll("\\.", ","));
System.out.println("qwe.rty.yui.uio".replace(".", ","));
// 11 String[] split(String regex) : Split string , Return string array , regular expression , Be careful .....
// spot , Need to escape
String s2 = "2022.1.14";
String[] arr = s2.split("\\.");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
// 12 String substring(int begin); In the string , Substring starting with a subscript ( contain )
System.out.println("abcdef".substring(2));// cdef
// 13 String substring(int begin, int end) :
// In the string , Start with a subscript ( contain ) Substring ending at a subscript ( It doesn't contain )
System.out.println("abcdef".substring(2, 4));// cd
// 14 String trim() : Remove the spaces on both sides of the string
System.out
.println(" a d sadasd ");
System.out
.println(" a d sadasd "
.trim());
// 15 String toUpperCase() : Turn capitalization
// String toLowerCase() : Turn lowercase
System.out.println("asd".toUpperCase());
// 16 static String valueOf(Object obj) :
// Calling the toString Method , If null, No more calls toString Instead, it returns a string null
String_05 s = null;
// When printing a reference type , Automatically called String Of valueOf therefore Automatically called toString Method
System.out.println(s);
1、6 Be careful




2、StringBuffer and StringBuilder
2、1 summary

2、2 Basic use

2、3 Common methods

3、 Packaging
3、1 summary
【 ask 】 Want to do more with basic type data , What do I do ?
【 answer 】 The most convenient way is to encapsulate it as an object . Because more properties and behaviors can be defined in the object description to operate on the basic data type . We don't need to encapsulate basic types by ourselves ,JDK It has been encapsulated for us .
【 Concept 】
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

3.3 Integer
3.3.1 Basic use

3.3.2 transformation

3.3.3 Common methods

3.3.4 Automatic packing and unpacking


3.3.5、 Deep shaping constant pool

Judge the current value Whether in -128~127 Between
If it's not in range Just directly new object




3.3.6 summary


4.System
4.1 summary
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 .
Member variables
System Class contains in、out and err Three member variables , They represent the standard input stream
( Keyboard entry ), Standard output stream ( Monitor ) And standard error output stream ( Monitor ).
Member method
native long currentTimeMillis():
The function of this method is to return the current computer time , Time is expressed in the current computer
Between and GMT Time ( Greenwich mean time )1970 year 1 month 1 Number 0 when 0 branch 0 The number of milliseconds in seconds .
void exit(int status):
The function of this method is to exit the program . among status The value of is 0 It means normal exit , Non zero means
Abnormal exit . Using this method, the exit function of program can be realized in GUI programming .
4.2 Common methods

5.Date
5.1 summary
Get time and time operations
5.2 Construction method

5.3 Common methods

5.4 format

5.5 Calendar

6. Random
6.1 summary Random number from 0 Start
6.2 Use
边栏推荐
- Golang operation redis: write and read hash type data
- 4279. Cartesian tree
- Redis command
- IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
- Shim and Polyfill in [concept collection]
- Daily question brushing record (11)
- Setting up the development environment of dataworks custom function
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
- Understand software testing
- 卡特兰数(Catalan)的应用场景
猜你喜欢

Reading notes of "learn to ask questions"

熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?

Pits encountered in the use of El checkbox group

机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)

3311. Longest arithmetic

2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)

Arctic code vault contributor

These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products

JUC forkjoinpool branch merge framework - work theft

691. 立方体IV
随机推荐
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
PHP install composer
Advanced API (local simulation download file)
Laravel Web框架
How to plan well?
New knowledge! The virtual machine network card causes your DNS resolution to slow down
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
PAT甲级真题1166
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
10000小时定律不会让你成为编程大师,但至少是个好的起点
Software testing learning - the next day
php artisan
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
2021 year end summary
Advanced API (serialization & deserialization)
Shim and Polyfill in [concept collection]
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
golang操作redis:写入、读取kv数据
CentOS php7.3 installing redis extensions
